bingxuan9112

lockout!

Feb 24th, 2020
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import requests
  4. from bs4 import BeautifulSoup
  5. from random import choice
  6. import json
  7. from datetime import datetime
  8.  
  9. handles = ['Omelet', '03t', 'Kevin_Zhang', '我在膜拜祢', 'eric_xiao', 'cwcodinglife']
  10. probs = [1166, 1040, 1137, 1445, 1787]
  11.  
  12.  
  13. def getranklist(pid):
  14.     res = requests.get(f'https://tioj.ck.tp.edu.tw/problems/{str(pid)}/ranklist')
  15.     soup = BeautifulSoup(res.text, features="lxml")
  16.     rk = soup.find_all('tr')[1:]
  17.     return sorted(list([
  18.         (lambda s: { 'sid': s[1], 'handle': s[3], 'time': datetime.strptime(s[8], "%Y-%m-%d %H:%M:%S")})(
  19.             [tag.text for tag in row.find_all('td')]
  20.         )
  21.     for row in rk]), key = lambda s: s['time'])
  22.  
  23. score = {}
  24. firstac = {}
  25. for handle in handles:
  26.     score[handle] = 0
  27. for prob in probs:
  28.     for user in getranklist(prob):
  29.         handle = user['handle']
  30.         if handle in handles:
  31.             score[handle] += 1
  32.             firstac[prob] = handle
  33.             break
  34.  
  35. print(score)
  36. print(firstac)
Advertisement
Add Comment
Please, Sign In to add comment