Skip to content

Instantly share code, notes, and snippets.

@Celeo
Created June 26, 2017 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Celeo/9a2b4099b98772c1575283c93e13ad1d to your computer and use it in GitHub Desktop.
Save Celeo/9a2b4099b98772c1575283c93e13ad1d to your computer and use it in GitHub Desktop.
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