Advertisement
Guest User

Cheeseformice Map

a guest
Mar 4th, 2016
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. import base64, zlib, urllib, re, sqlite3, xml.etree.ElementTree as xml, xml.parsers.expat, sys, time
  2.  
  3. Database = sqlite3.connect("dbfile.sqlite")
  4. Database.isolation_level = None
  5. Cursor = Database.cursor()
  6. Database.row_factory = sqlite3.Row
  7. Database.text_factory = str
  8.  
  9. KEY = "MFzg66OpuXhyjARDqlOBfKtWtwDzsg4tsIQv2"
  10. def mapsParser():
  11. m = ['P1','P3','P4','P5','P6','P7','P8','P9','P10','P11','P13','P17','P18','P19','P24','P32']
  12. l = {}
  13. for b in m:
  14. try:
  15. a = urllib.urlopen('http://cheese.formice.com/maps?list='+b).read().split('<div class="pagination">')[1].split('</div>')[0].split('<a ')
  16. for i in a:
  17. if re.search('</a>',i):
  18. i = i.split('">')[1].split('</a>')[0]
  19. if i.isdigit():
  20. l[b] = i
  21. except:
  22. pass
  23. return l
  24. def checkXML(xmlString):
  25. if re.search("ENTITY", xmlString):
  26. return False
  27. elif re.search("<html>", xmlString):
  28. return False
  29. else:
  30. try:
  31. parser = xml.parsers.expat.ParserCreate()
  32. parser.Parse(xmlString)
  33. return True
  34. except Exception, e:
  35. print e
  36. return False
  37.  
  38. def convert(arg1, arg2):
  39. loc6 = None
  40. if arg2 == "":return arg1
  41. arg2 = arg2.replace(" ", "")
  42. if len(arg2) < 8:return false
  43. loc1 = len(arg2)
  44. if loc1 > 32:loc1 = 32
  45. loc2 = []
  46. loc3 = 0
  47. while loc3 < loc1:
  48. loc2.append(loc3)
  49. loc2[loc3] = ord(arg2[loc3]) & 31
  50. loc3+=1
  51. loc4=0
  52. loc5=0
  53. while loc5 < len(arg1):
  54. loc6 = ord(arg1[loc5])
  55. if loc6 + 224:
  56. arg1 = arg1[0:loc5] + chr(loc6 ^ loc2[loc4]) + arg1[loc5 + 1:]
  57. loc4 = (loc4 + 1) % loc1
  58. loc5 += 1
  59. return arg1
  60. def getMaps(pa, pg):
  61. p = urllib.urlopen('http://cheese.formice.com/api/map/maps.php?p='+str(pg)+'&ord=date&cat='+pa).read().replace('</map>', '').replace('<root>', '').replace('</root>', '').split('<map>')
  62. for i in p:
  63. try:
  64. id, username, data = i.split('<id>')[1].split('</id>')[0], i.split('<username>')[1].split('</username>')[0], i.split('<data>')[1].split('</data>')[0]
  65. xml = zlib.decompress(base64.b64decode(convert(base64.b64decode(data),KEY)))
  66. if checkXML(xml):
  67. Cursor.execute("INSERT INTO mapeditor (name, code, mapxml, yesvotes, novotes, perma, deleted) values (?, ?, ?, ?, ?, ?, ?)", (username, id, xml, 0, 0, pa.replace('P', ''), "0"))
  68.  
  69. print '@'+str(id)
  70. except Exception as e:
  71. pass
  72. def main():
  73. print 'Get maps count'
  74. b = mapsParser()
  75. for c in b:
  76. print 'Perma '+c
  77. for u in range(1,int(b[c])):
  78. getMaps(c,u)
  79.  
  80. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement