Skip to content

Instantly share code, notes, and snippets.

@rweichler
Last active February 23, 2020 05:24
Show Gist options
  • Save rweichler/f2f10a63188f70be394bec7fd8d9ac72 to your computer and use it in GitHub Desktop.
Save rweichler/f2f10a63188f70be394bec7fd8d9ac72 to your computer and use it in GitHub Desktop.
import presets from eqe.fm
#!/usr/bin/env python2
# HOW TO USE:
# Download this file
# Install python 2
# Run one of these commands (depends on your setup):
# python2 eqefm_import.py 1
# python eqefm_import.py 1
# python2.exe eqefm_import.py 1
# python.exe eqefm_import.py 1
# Replace the 1 with whatever your userid is.
# You can find it based on the url from https://eqe.fm/user
import json
import requests
import sys
import os
if len(sys.argv) != 2:
print('error: need userid')
exit(1)
if not sys.argv[1].isdigit():
print('error: userid must be number')
exit(1)
def api(method):
resp = requests.get('https://eqe.fm/api/' + method)
if resp.status_code != 200:
try:
json = resp.json()
print('error: ' + json['error'])
except Exception:
print('error: bad response from server: ' + str(resp.status_code))
exit(1)
return resp.json()
presets = api('presets?user=' + sys.argv[1])
user = api('user?user=' + sys.argv[1])
if not os.path.exists(user['username']):
print('Creating directory "' + user['username'] + '"')
os.mkdir(user['username'])
for preset in presets:
path = user['username'] + '/' + preset['name'] + '.lua'
print('creating "' + path + '"')
f = open(path, 'w')
f.write('return {\n')
for band in preset['data']:
f.write(' {\n')
for k in band:
v = band[k]
if isinstance(v, basestring):
v = v.replace('\n', '\\n')
v = v.replace('\r', '\\r')
v = v.replace('\t', '\\t')
v = v.replace('"', '\\"')
f.write(' ["' + k + '"] = "' + v + '",\n')
else:
f.write(' ["' + k + '"] = ' + str(v) + ',\n')
f.write(' },\n')
f.write('}')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment