Last active
June 11, 2019 18:18
-
-
Save limitedeternity/07cb54c2f2f7cbfad2380986675469db to your computer and use it in GitHub Desktop.
Collects all russian universities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vk | |
import json | |
import time | |
session = vk.Session( | |
access_token='token_with_offline_scope') | |
api = vk.API(session, v='5.95', lang='ru') | |
JSON = {"cities": []} | |
counter = 1 | |
while counter <= 1500: | |
try: | |
city = api.database.getCitiesById(city_ids=counter) | |
if city[0]['title']: | |
univers = api.database.getUniversities( | |
country_id=1, city_id=counter, count=10000) | |
city[0]['universities'] = univers['items'] | |
JSON['cities'].append(city) | |
counter += 1 | |
except KeyboardInterrupt: | |
break | |
except vk.exceptions.VkAPIError as e: | |
try: | |
print(e) | |
time.sleep(0.5) | |
except KeyboardInterrupt: | |
break | |
with open('data.json', 'w', encoding='utf8') as json_file: | |
json.dump( | |
JSON, json_file, ensure_ascii=False, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment