Skip to content

Instantly share code, notes, and snippets.

@judge2020
Created January 5, 2018 21:14
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 judge2020/701bb57128eb21681a61301a295e401b to your computer and use it in GitHub Desktop.
Save judge2020/701bb57128eb21681a61301a295e401b to your computer and use it in GitHub Desktop.
migrate users.ini to usersDB.json
import pprint
import json
from configobj import ConfigObj
pp = pprint.PrettyPrinter(indent=4)
db = ConfigObj(infile='users.ini')
tmp = db['suggestion_count']
def get_suggestion_upvotes(userid):
try:
ups = tmp[str(userid)]["ups"]
except:
ups = 0
return ups
def get_suggestion_downvotes(userid):
try:
downs = tmp[str(userid)]["downs"]
except:
downs = 0
return downs
db = {}
for key in tmp:
db[key] = [get_suggestion_upvotes(key), get_suggestion_downvotes(key)]
#print(str(key) + str(get_suggestion_upvotes(key)) + str(get_suggestion_downvotes(key)))
newdb = json.load(open('usersDB.json', 'r'))
for key, value in db.items():
try:
usr = newdb[key]
except:
newdb[key] = {}
usr = newdb[key]
try:
sugc = usr["suggestion_count"][0]
except:
usr["suggestion_count"] = [{}]
sugc = usr["suggestion_count"][0]
try:
uuv = sugc["uv"]
except:
sugc["uv"] = 0
uuv = sugc["uv"]
try:
udv = sugc["dv"]
except:
sugc["dv"] = 0
udv = sugc["dv"]
sugc["uv"] = uuv + int(value[0])
sugc["dv"] = udv + int(value[1])
with open('newusersdb.json', 'w') as f:
json.dump(newdb, f)
@judge2020
Copy link
Author

pretty hacky i know but worked

@xseano
Copy link

xseano commented Jan 5, 2018

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment