SHARE
TWEET

Untitled

lalalalalalalaalalla Jul 4th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. import re
  3.  
  4. file = open("all_themes2.txt", "w", encoding='utf-8')
  5. text = requests.get("http://hecs.info/").text
  6. file.write(text)
  7. all_pages = re.findall(r'<a href="theme/(.*?)">\s*?<div class=" hexagon hex_link (.*?)">', text)
  8. url = "http://hecs.info/theme/{}"
  9.  
  10. all_themes = {}
  11.  
  12. for subtheme in all_pages:
  13.     if subtheme[0] == "581": continue
  14.     try:
  15.         text = requests.get(url.format(subtheme[0])).text
  16.     except:
  17.         # print("ERROR", subtheme)
  18.         continue
  19.     name = re.findall(r'<title>(.*?)</title>', text)
  20.     template = r'<span class="target .*?">(.*&?)</span> <a target="_blank" href="(.*?)"'
  21.  
  22.     material = list(set(re.findall(template, text)))
  23.     # print(material)
  24.     task = []
  25.     for val in material:
  26.         if val[0].lower() == "informatics":
  27.             task = val
  28.             break
  29.     description = "nil"
  30.     # description = requests.get('https://ru.wikipedia.org/w/api.php?action=opensearch&search={}&prop=info&format=xml&inprop=url'.format(name.lower())).text
  31.     if task: material.remove(task)
  32.     if subtheme[1] in all_themes:
  33.         all_themes[subtheme[1]] += ['Subtheme(\n   name: "{}",\n   description: "{}",\n   material: {},\n   tasks: {}),\n'.format(name[0], description, material, task)]
  34.     else:
  35.         all_themes[subtheme[1]] = ['Subtheme(\n   name: "{}",\n   description: "{}",\n   material: {},\n   tasks: {}),\n'.format(name[0], description, material, task)]
  36.  
  37.  
  38. for i in all_themes:
  39.     if i == "hex_rec0":
  40.         nameTheme = "Рекурсия"
  41.     elif i == "hex_graph0":
  42.         nameTheme = "Графы"
  43.     elif i == "hex_search0":
  44.         nameTheme = "Поиск"
  45.     elif i == "hex_sort0":
  46.         nameTheme = "Сортировки"
  47.     elif i == "hex_dp0":
  48.         nameTheme = "Динамическое программирование"
  49.     elif i == "hex_geom0":
  50.         nameTheme = "Геометрия"
  51.     elif i == "hex_comb0":
  52.         nameTheme = "Комбинаторика"
  53.     elif i == "hex_data0":
  54.         nameTheme = "Структуры данных"
  55.     elif i == "hex_str0":
  56.         nameTheme = "Строки"
  57.     elif i == "hex_nums0":
  58.         nameTheme = "Числа"
  59.     elif i == "hex_eq0":
  60.         nameTheme = "Уравнения"
  61.     elif i == "hew_start":
  62.         continue
  63.     else:
  64.         nameTheme = "Прочее"
  65.         print("ErrorErrorError")
  66.  
  67.     file.write('Theme(name: "{}", subt: [\n'.format(nameTheme))
  68.     for elem in all_themes[i]:
  69.         file.write(elem)
  70.     file.write(']),\n')
  71.  
  72. file.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top