Advertisement
Guest User

Untitled

a guest
Aug 8th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import MySQLdb, os, json, collections
  3.  
  4. class exportMaps:
  5.     def __init__(self):
  6.         self.db = None
  7.         self.cursor = None
  8.  
  9.         self.dbConnection()
  10.         self.exportMaps()
  11.         self.log("Mapas exportados com êxito")
  12.  
  13.     def log(self, m):
  14.         print m
  15.  
  16.     def dbConnection(self):
  17.         """
  18.         Função responsável por fazer a conexão com o banco a partir dos dados fornecidos
  19.         """
  20.         self.db = MySQLdb.connect(
  21.             host=raw_input("Host: "),
  22.             user=raw_input("User: "),
  23.             passwd=raw_input("Password: "),
  24.             db=raw_input("Database: "))
  25.         self.cursor = self.db.cursor()
  26.         self.log("[Conexão estabelecida]")
  27.  
  28.     def exportMaps(self):
  29.         """
  30.         Função responsável por exportar os mapas de uma coluna fornecida pelo
  31.         usuário e será salvo em um arquivo JSON
  32.         """
  33.         self.cursor("SELECT * from %s" % (raw_input("Coluna da DB: ")))
  34.         self.log("Exportando Mapas")
  35.  
  36.         res, maps = self.cursor.fetchall(), []
  37.         for mapa in res:
  38.             d = collections.OrderedDict()
  39.             d["Code"] = mapa[0]
  40.             d["Name"] = mapa[1]
  41.             d["XML"]  = mapa[2]
  42.             mapas.append(d)
  43.  
  44.         self.log("Salvando Mapas")
  45.         with open("maps.json", "w") as file:
  46.             json.dump(mapas, file)
  47.  
  48. if __name__ == "__main__":
  49.     print ("Welcome to MapsDump MySQL\nVersion: 0.1\nDeveloped by RodrigoArcres - Nikopark")
  50.     print ("ter all MySQL data")
  51.     exportMaps()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement