Advertisement
tuki2501

stalker.py

Nov 21st, 2021 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. import json, re, sys
  2. from urllib.request import Request, urlopen
  3.  
  4. # https://sangnd.wordpress.com/2014/01/03/python-chuyen-tieng-viet-co-dau-thanh-khong-dau/
  5.  
  6. patterns = {
  7.   '[àáảãạăắằẵặẳâầấậẫẩ]': 'a',
  8.   '[đ]': 'd',
  9.   '[èéẻẽẹêềếểễệ]': 'e',
  10.   '[ìíỉĩị]': 'i',
  11.   '[òóỏõọôồốổỗộơờớởỡợ]': 'o',
  12.   '[ùúủũụưừứửữự]': 'u',
  13.   '[ỳýỷỹỵ]': 'y'
  14. }
  15.  
  16. def convert(text):
  17.   output = text
  18.   for regex, replace in patterns.items():
  19.       output = re.sub(regex, replace, output)
  20.       # deal with upper case
  21.       output = re.sub(regex.upper(), replace.upper(), output)
  22.   return output
  23.  
  24. # ----------------------------------------------------------------------------------------
  25.  
  26. user_id  = input()
  27. rival_id = input()
  28.  
  29. user_url  = Request("https://oj.vnoi.info/api/v2/user/"+user_id, headers={'User-Agent': 'Mozilla/5.0'})
  30. user_json = json.loads(urlopen(user_url).read())
  31. user_list = user_json['data']['object']['solved_problems']
  32.  
  33. rival_url  = Request("https://oj.vnoi.info/api/v2/user/"+rival_id, headers={'User-Agent': 'Mozilla/5.0'})
  34. rival_json = json.loads(urlopen(rival_url).read().decode())
  35. rival_list = rival_json['data']['object']['solved_problems']
  36.  
  37. tags = dict()
  38.  
  39. for prob in user_list:
  40.   prob_url  = Request("https://oj.vnoi.info/api/v2/problem/"+prob, headers={'User-Agent': 'Mozilla/5.0'})
  41.   prob_json = json.loads(urlopen(prob_url).read())
  42.   prob_tags = prob_json['data']['object']['types']
  43.   for tag in prob_tags:
  44.     if tag in tags:
  45.       tags[tag][0] += 1
  46.     else:
  47.       tags[tag] = [1, 0]
  48.  
  49. for prob in rival_list:
  50.   prob_url  = Request("https://oj.vnoi.info/api/v2/problem/"+prob, headers={'User-Agent': 'Mozilla/5.0'})
  51.   prob_json = json.loads(urlopen(prob_url).read())
  52.   prob_tags = prob_json['data']['object']['types']
  53.   for tag in prob_tags:
  54.     if tag in tags:
  55.       tags[tag][1] += 1
  56.     else:
  57.       tags[tag] = [0, 1]
  58.  
  59. print('Bai doi thu da lam nhung ban thi chua:')
  60.  
  61. for prob in user_list:
  62.   if (prob in rival_list):
  63.     rival_list.remove(prob)
  64.  
  65. for prob in rival_list:
  66.   print(prob)
  67.  
  68. print()
  69.  
  70. print('So bai ban va doi thu da lam theo dang:')
  71.  
  72. for tag in tags:
  73.   print(convert(tag),':',tags[tag])
  74.  
  75. print()
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement