Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import MySQLdb, os, json, collections
- class exportMaps:
- def __init__(self):
- self.db = None
- self.cursor = None
- self.dbConnection()
- self.exportMaps()
- self.log("Mapas exportados com êxito")
- def log(self, m):
- print m
- def dbConnection(self):
- """
- Função responsável por fazer a conexão com o banco a partir dos dados fornecidos
- """
- self.db = MySQLdb.connect(
- host=raw_input("Host: "),
- user=raw_input("User: "),
- passwd=raw_input("Password: "),
- db=raw_input("Database: "))
- self.cursor = self.db.cursor()
- self.log("[Conexão estabelecida]")
- def exportMaps(self):
- """
- Função responsável por exportar os mapas de uma coluna fornecida pelo
- usuário e será salvo em um arquivo JSON
- """
- self.cursor("SELECT * from %s" % (raw_input("Coluna da DB: ")))
- self.log("Exportando Mapas")
- res, maps = self.cursor.fetchall(), []
- for mapa in res:
- d = collections.OrderedDict()
- d["Code"] = mapa[0]
- d["Name"] = mapa[1]
- d["XML"] = mapa[2]
- mapas.append(d)
- self.log("Salvando Mapas")
- with open("maps.json", "w") as file:
- json.dump(mapas, file)
- if __name__ == "__main__":
- print ("Welcome to MapsDump MySQL\nVersion: 0.1\nDeveloped by RodrigoArcres - Nikopark")
- print ("ter all MySQL data")
- exportMaps()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement