Skip to content

Instantly share code, notes, and snippets.

@nguyentienlong
Last active September 22, 2020 04:18
Show Gist options
  • Save nguyentienlong/79a1bd1da8d08f38ef8bb378ad70cb8a to your computer and use it in GitHub Desktop.
Save nguyentienlong/79a1bd1da8d08f38ef8bb378ad70cb8a to your computer and use it in GitHub Desktop.
uprace - get team member stats

prerequisite

python3
requests

If your computer not install requests lib yet

pip install requests

To get teammates info

python crawl_uprace.py > ~/Downloads/teammates_info.csv

Then open ~/Downloads/teammates_info.csv for more detail

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func main() {
url := "https://api.uprace.vn/api/event/rank/list"
payload := `
{
"trid":"6d78c2b7-059b-4192-858e-74443d27c8ea",
"trtm":1600589548,
"data":{
"from": 0,
"size": 1,
"evid":2,
"type":1,
"sex":0,
"name":"",
"value":93
}
}
`
//var f interface {}
resp, err := http.Post(url, "application/json", strings.NewReader(payload))
if err != nil {
panic(err)
}
data, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
panic(err)
}
m := make(map[string]interface{})
err = json.Unmarshal(data, &m)
m_data, ok := m["data"].(map[string]interface{})
total_mem := 0
if ok {
total_mem = int(m_data["total"].(float64))
}
page_size := 100
total_page := int(total_mem/page_size + 1)
fmt.Printf("%d %d %d\n", total_mem, page_size, total_page)
for i := 0; i < total_page; i++ {
payload = fmt.Sprintf(`
{
"trid":"6d78c2b7-059b-4192-858e-74443d27c8ea",
"trtm":1600589548,
"data":{
"from": %d,
"size": %d,
"evid":2,
"type":1,
"sex":0,
"name":"",
"value":93
}
}`, i*page_size, page_size)
resp, err := http.Post(url, "application/json", strings.NewReader(payload))
if err != nil {
panic(err)
}
data, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
panic(err)
}
type Member struct {
Id int
Name string
Sex int
Rank int
City string
Ctry string
Ava string
}
type UpRaceResp struct {
Data struct {
List []Member
}
}
var uResp UpRaceResp
if err = json.Unmarshal(data, &uResp); err != nil {
panic(err)
}
fmt.Printf("mem.Id,mem.Name,mem.Sex,mem.Rank,mem.City,mem.Ctry,mem.Ava\n")
for _, mem := range uResp.Data.List {
fmt.Printf("%d,%s,%d,%d,%s,%s,%s\n", mem.Id, mem.Name, mem.Sex, mem.Rank, mem.City, mem.Ctry, mem.Ava)
}
}
}
import requests
page_size = 100
url = "https://api.uprace.vn/api/event/rank/list"
# get total members
payload = {
"trid":"6d78c2b7-059b-4192-858e-74443d27c8ea",
"trtm":1600589548,
"data":{
"from": 0,
"size": 1,
"evid":2,"type":1,"sex":0,"name":"","value":93
}
}
res = requests.post(url, json=payload)
total_mem = res.json()['data']['total']
total_page = int(total_mem / page_size) + 1
print('id, name, sex, rank, city, ctry, tmnm, ava')
for i in range(0, total_page):
payload = {
"trid":"6d78c2b7-059b-4192-858e-74443d27c8ea",
"trtm":1600589548,
"data":{
"from": i*page_size,
"size": page_size,
"evid":2,"type":1,"sex":0,"name":"","value":93
}
}
res = requests.post(url, json=payload)
for mem in res.json()['data']['list']:
print('{},{},{},{},{},{},{},{}'.format(
mem["id"],
mem["name"], mem["sex"], mem["rank"], mem["city"], mem["ctry"],
mem["tmnm"], mem["ava"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment