Advertisement
Guest User

Untitled

a guest
Aug 9th, 2019
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup, SoupStrainer
  3. import json
  4. import matplotlib.pyplot as plt
  5. import time
  6.  
  7. rank = 0
  8. ranking = BeautifulSoup(open("rank.html", "r", encoding="utf8").read())
  9. contestants = BeautifulSoup(open("contestants.html", "r", encoding="utf8").read())
  10. requrl = ''
  11. ranklist = []
  12. for contestant in ranking.find_all('tr', class_='user'):
  13.     rank+=1
  14.     contestantname = contestant.contents[5].string + ' ' + contestant.contents[7].string
  15.     cfhandle = ''
  16.     if contestantname=='Ekrem BAL':
  17.         contestantname = 'Ekrem Bal'
  18.  
  19.     if contestants.find(string=contestantname)==None:
  20.         continue
  21.     name = contestants.find(string=contestantname).parent.parent.parent
  22.     for att in name.find_all('a'):
  23.         if att.has_attr('href') and 'codeforces.com' in att['href']:
  24.             cfhandle = att['href']
  25.     if cfhandle=='':
  26.         continue
  27.     cfhandle = cfhandle.split('/')[-1]
  28.     if cfhandle=='nasic_number_one':
  29.         cfhandle = 'NeKrasnyj'
  30.     if cfhandle=='nikabb':
  31.         cfhandle = 'saba2000'
  32.     if cfhandle=='___tutis___':
  33.         cfhandle = '__.__'
  34.     if cfhandle=='YaDon4ick':
  35.         cfhandle = 'YaKon4ick'
  36.     if cfhandle=='Rudy420':
  37.         cfhandle = 'Rudy358'
  38.     if cfhandle=='iLoveChai':
  39.         cfhandle = 'whipppedcream'
  40.     if cfhandle=='reality420':
  41.         cfhandle = 'I_Love_Tina'
  42.     if cfhandle=='jiajunlee':
  43.         cfhandle = '2xJelly'
  44.     if cfhandle=='Muhanad_Alwarareh':
  45.         cfhandle = 'Warawreh'
  46.     if cfhandle=='NaderJemel':
  47.         cfhandle = 'nader'
  48.     if cfhandle=='muradeyn':
  49.         cfhandle = 'wthIC'
  50.     if cfhandle=='The_Pain_Inside_':
  51.         cfhandle = 'LoveAnimeDesu'
  52.     if cfhandle=='mraron':
  53.         cfhandle = 'sanroylozan'
  54.     if cfhandle=='oscarsierra12':
  55.         cfhandle = 'oscarsierra007'
  56.     if cfhandle=='claudy':
  57.         cfhandle = '4everOrange'
  58.     if cfhandle=='Mahmoud..Adel':
  59.         cfhandle = 'BL7A.'
  60.     if cfhandle=='arturoaureliohr':
  61.         cfhandle = '_Shush'
  62.        
  63.        
  64.        
  65.     requrl+=cfhandle+';'
  66.     ranklist.append(rank)
  67. print(requrl[0:-1])
  68. r = requests.get('https://codeforces.com/api/user.info?handles='+requrl[0:-1])
  69. print(r.content)
  70. r = json.loads(r.content)
  71. ratings = []
  72. for i in range(len(ranklist)):
  73.     ratings.append(r['result'][i]['rating'])
  74.  
  75. print(ratings)
  76. plt.scatter(ranklist, ratings)
  77. plt.ylabel('Codeforces Rating')
  78. plt.xlabel('IOI Rank')
  79. plt.axvspan(0, 28, facecolor='#D4AF37', alpha=0.5)
  80. plt.axvspan(28, 84, facecolor='#C0C0C0', alpha=0.5)
  81. plt.axvspan(84, 164, facecolor='#CD7F32', alpha=0.5)
  82. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement