mirror of
https://github.com/thebaer/tildes.git
synced 2018-07-20 07:15:21 +00:00
Show user's local time
This commit is contained in:
parent
feb0786090
commit
dca3c0131a
@ -8,10 +8,15 @@
|
||||
<style type="text/css">
|
||||
div.user {
|
||||
margin: 0;
|
||||
width: 50em;
|
||||
}
|
||||
div.user h2 {
|
||||
margin: 0;
|
||||
}
|
||||
span.time {
|
||||
float: right;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
@ -23,7 +28,7 @@
|
||||
|
||||
{{range .Users}}
|
||||
<div class="user">
|
||||
<h2><a href="/~{{.Name}}/">~{{.Name}}</a></h2> <span class="location">{{Location .Region .Country}}</span>
|
||||
<h2><a href="/~{{.Name}}/">~{{.Name}}</a></h2> <span class="location">{{Location .Region .Country}} </span> <span class="time">{{.CurrentTime}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
@ -37,6 +37,7 @@ type User struct {
|
||||
IP string
|
||||
Region string
|
||||
Country string
|
||||
CurrentTime string
|
||||
}
|
||||
|
||||
var ipRegex = regexp.MustCompile("(([0-9]{1,3}[.-]){3}[0-9]{1,3})")
|
||||
@ -85,6 +86,26 @@ func who() []User {
|
||||
return users
|
||||
}
|
||||
|
||||
func getTimeInZone(tz string) string {
|
||||
cmd := exec.Command("date", "+%A %H:%M")
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("TZ=%s", tz))
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err := cmd.Start(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
r := bufio.NewReader(stdout)
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
return scanner.Text()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getGeo(u *User) {
|
||||
fmt.Printf("Fetching %s location...\n", u.Name)
|
||||
|
||||
@ -109,6 +130,7 @@ func getGeo(u *User) {
|
||||
region := dat["region_name"].(string)
|
||||
country := dat["country_name"].(string)
|
||||
|
||||
u.CurrentTime = getTimeInZone(dat["time_zone"].(string))
|
||||
u.Region = region
|
||||
u.Country = country
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user