Created
June 26, 2017 03:46
-
-
Save Celeo/9a2b4099b98772c1575283c93e13ad1d to your computer and use it in GitHub Desktop.
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 sqlite3 | |
from preston.xmlapi import Preston | |
connection = sqlite3.connect('data.db') | |
cursor = connection.cursor() | |
cursor.execute('SELECT character_name FROM member') | |
character_names = [e[0] for e in cursor.fetchall()] | |
characters = [] | |
api = Preston() | |
chunks = zip(*(iter(character_names), ) * 25) | |
for index, chunk in enumerate(chunks): | |
print(f'Fetching batch #{index + 1} of characters') | |
r = api.eve.CharacterID(names=','.join(chunk)) | |
for e in r['rowset']['row']: | |
characters.append((e['@characterID'], e['@name'])) | |
print('Updating database ...', end='') | |
for e in characters: | |
cursor.execute('UPDATE member SET character_id=? WHERE character_name=?', e) | |
print('done\nCommitting changes ...', end='') | |
connection.commit() | |
connection.close() | |
print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment