import_wiimm_data.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. """Import the profile and friend data collected from the GameSpy servers by Wiimm
  2. Put all *-nick and *-fc files to be imported into t into the data folder and then run this program to import them
  3. into the database.
  4. This may take some time to import all of the data on bigger files if you check if each entry is already in the database.
  5. """
  6. import glob
  7. import sys
  8. sys.path.append('../')
  9. import gamespy.gs_database as gs_database
  10. db = gs_database.GamespyDatabase()
  11. pid = "11"
  12. lon = "0.000000"
  13. lat = "0.000000"
  14. loc = ""
  15. stat = ""
  16. partnerid = ""
  17. password = ""
  18. userid = ""
  19. csnum = ""
  20. cfc = ""
  21. bssid = ""
  22. devname = ""
  23. birth = ""
  24. nicks = {}
  25. #"CREATE TABLE users (profileid INT, userid TEXT, password TEXT, gsbrcd TEXT, email TEXT, uniquenick TEXT, pid TEXT, lon TEXT, lat TEXT, loc TEXT, firstname TEXT, lastname TEXT, stat TEXT, partnerid TEXT, console INT, csnum TEXT, cfc TEXT, bssid TEXT, devname TEXT, birth TEXT, sig TEXT)"
  26. for nickfile in glob.glob("data/*-nick"):
  27. conn = db.conn
  28. c = conn.cursor()
  29. print "Parsing %s..." % nickfile
  30. cnt = 0
  31. for line in open(nickfile):
  32. s = line.lstrip().split(' ')
  33. if s[0] not in nicks:
  34. nicks[s[0]] = 1
  35. profileid = int(s[0])
  36. uniquenick = s[1]
  37. # Uncomment to check if the user exists before inserting, but it slows down things greatly.
  38. #if db.check_profile_exists(profileid) is not None:
  39. # pass
  40. firstname = s[2]
  41. if firstname == "-":
  42. firstname = ""
  43. lastname = s[2]
  44. if lastname == "-":
  45. lastname = ""
  46. email = s[3]
  47. gsbrcd = uniquenick[9:]
  48. gameid = gsbrcd[:4]
  49. console = 0
  50. if firstname[:4] == "Wii:":
  51. console = 1
  52. if cnt == 0:
  53. conn.execute("begin")
  54. #print "Importing %d %s %s %s %s %s %s %d" % (profileid, uniquenick, firstname, lastname, email, gsbrcd, gameid, console)
  55. q = "INSERT INTO users VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
  56. c.execute(q, [profileid, str(userid), password, gsbrcd, email, uniquenick, pid, lon, lat, loc, firstname, lastname, stat, partnerid, console, csnum, cfc, bssid, devname, birth, gameid])
  57. cnt += 1
  58. if cnt >= 50000:
  59. print "%d nicks inserted..." % len(nicks)
  60. conn.commit()
  61. cnt = 0
  62. conn.commit()
  63. c.close()
  64. nicks = {}
  65. #"CREATE TABLE buddies (userProfileId INT, buddyProfileId INT, time INT, status INT, notified INT, gameid TEXT)"
  66. fcs = {}
  67. status = 1 # Assume everyone has already accepted everyone else
  68. notified = 1 # Assume that everyone has already been sent the notification
  69. time = 0
  70. for fcfiles in glob.glob("data/*-fc"):
  71. conn = db.conn
  72. c = conn.cursor()
  73. print "Parsing %s..." % fcfiles
  74. cnt = 0
  75. for line in open(fcfiles):
  76. s = line.split(' ')
  77. s = [x for x in s if x] # Remove any blank elements
  78. if s[1] not in fcs:
  79. fcs[s[1]] = 1
  80. userProfileId = int(s[1])
  81. gameid = s[2]
  82. if cnt == 0:
  83. conn.execute("begin")
  84. for friend in s[4:]:
  85. friend = friend.strip()
  86. if not friend or friend == '':
  87. continue
  88. buddyProfileId = int(friend)
  89. q = "INSERT INTO buddies VALUES (?,?,?,?,?,?)"
  90. c.execute(q, [userProfileId, buddyProfileId, time, status, notified, gameid])
  91. cnt += 1
  92. if cnt >= 50000:
  93. print "%d buddies inserted..." % len(fcs)
  94. conn.commit()
  95. cnt = 0
  96. conn.commit()
  97. c.close()
  98. fcs = {}