예제 #1
0
    def __init__(self):
        self.folder = '(папка):'
        self.path = ['/']
        self.old_path = ''
        self.old_name = ''
        self.to_delete = '0'
        self.api = Api('http://127.0.0.1:8000', 'admin', 'admin')
        self.root = Tk()

        self.root.geometry("400x250")

        self.listbox = Listbox(self.root, width=30, height=15)
        self.listbox.pack(side=LEFT)
        self.listbox.bind('<Double-1>', lambda x: self.listbox_click())
        self.fill_listbox()

        self.frame = Frame(self.root)
        self.frame.pack(side=LEFT)

        self.upload = Button(self.frame, text="Загрузить", command=self.upload)
        self.upload.pack()

        self.new_folder = Button(self.frame,
                                 text="Новая папка",
                                 command=self.new_folder)
        self.new_folder.pack()

        self.delete = Button(self.frame, text="Удалить", command=self.delete)
        self.delete.pack()

        self.copy = Button(self.frame,
                           text="Копировать",
                           command=self.copy_object)
        self.copy.pack()

        self.take = Button(self.frame, text="Вырезать", command=self.take)
        self.take.pack()

        self.paste = Button(self.frame, text="Вставить", command=self.paste)
        self.paste.pack()

        self.root.mainloop()
        pass
예제 #2
0
class Db():

    def __init__(self):

        self.country = Api("None")
        self.country.getApi()


    def setPais(self):

        self.mycursor = mydb.cursor()
        sql = "INSERT INTO datos (nombre,capital,habitantes) VALUES(%s,%s,%s)"
        val = (self.country.nombre, self.country.capital, self.country.poblacion)
        self.mycursor.execute(sql, val)
        mydb.commit()
        print(self.mycursor.rowcount, "registro ha sido insertado con exito.")

    def getDatos(self):

        self.mycursor = mydb.cursor()
        self.mycursor.execute("SELECT * FROM datos")
        self.myresult = self.mycursor.fetchall()
        """for result in self.myresult:
예제 #3
0
def menu():
    print("BIENVENIDO")
    while True:
        TrueDeparment = True
        limit = int(input("Ingrese el numero maximo de datos a buscar: "))
        while TrueDeparment:
            deparment = input("Ingrese el departamento(sin tilde): ")
            deparment = deparment.upper()
            if deparment not in all_deparments:
                print("Departamento no encontrado.")
                continue
            TrueDeparment = False
        result = Api.consult(limit, deparment)
        print(
            tabulate(result,
                     headers=[
                         'Ciudad', 'Departamento', 'Edad', 'Tipo', 'Estado',
                         'Procendencia'
                     ],
                     tablefmt='fancy_grid',
                     stralign='center'))
        next = input("Desea buscar mas datos?[Y/N]: ")
        if next == "N" or next == "n":
            break
예제 #4
0
class GUI:
    def __init__(self):
        self.folder = '(папка):'
        self.path = ['/']
        self.old_path = ''
        self.old_name = ''
        self.to_delete = '0'
        self.api = Api('http://127.0.0.1:8000', 'admin', 'admin')
        self.root = Tk()

        self.root.geometry("400x250")

        self.listbox = Listbox(self.root, width=30, height=15)
        self.listbox.pack(side=LEFT)
        self.listbox.bind('<Double-1>', lambda x: self.listbox_click())
        self.fill_listbox()

        self.frame = Frame(self.root)
        self.frame.pack(side=LEFT)

        self.upload = Button(self.frame, text="Загрузить", command=self.upload)
        self.upload.pack()

        self.new_folder = Button(self.frame,
                                 text="Новая папка",
                                 command=self.new_folder)
        self.new_folder.pack()

        self.delete = Button(self.frame, text="Удалить", command=self.delete)
        self.delete.pack()

        self.copy = Button(self.frame,
                           text="Копировать",
                           command=self.copy_object)
        self.copy.pack()

        self.take = Button(self.frame, text="Вырезать", command=self.take)
        self.take.pack()

        self.paste = Button(self.frame, text="Вставить", command=self.paste)
        self.paste.pack()

        self.root.mainloop()
        pass

    def copy_object(self):
        self.old_name = self.get_file_name()
        self.old_path = "/".join(self.path)

    def take(self):
        self.copy_object()
        self.to_delete = '1'

    def paste(self):
        self.api.paste(self.path, self.old_name, self.old_path, self.old_name,
                       self.to_delete)
        self.old_path = ''
        self.old_name = ''
        self.to_delete = '0'
        self.fill_listbox()

    def get_file_name(self):
        item = self.listbox.get('active')
        if item.find(self.folder) != -1:
            item = item.split(':')[1]
        return item

    def delete(self):
        self.api.delete(self.get_file_name(), self.path)
        self.fill_listbox()

    def fill_listbox(self):
        self.listbox.delete(0, END)
        out = self.api.file_list("/".join(self.path))
        files, directories = out.content.decode('utf-8').split('$')
        self.listbox.insert(END, "/")

        if len(directories) > 0:
            for item in directories.split(','):
                self.listbox.insert(END, self.folder + item)

        for item in files.split(','):
            self.listbox.insert(END, item)

    def upload(self):
        filepath = askopenfilename(initialdir="/home/oleg",
                                   title="Select file",
                                   filetypes=(("text", "*.txt"), ("all files",
                                                                  "*.*")))
        filename = filepath.split('/')[-1]
        files = {'file': (filename, open(filepath, 'rb'))}
        output = self.api.upload(file=files, path=self.path)
        self.listbox.insert(END, output.content.decode('utf-8'))
        self.fill_listbox()
        pass

    def new_folder(self):
        new_folder_modal = Toplevel(self.root)
        self.entry = Entry(new_folder_modal)
        self.entry.pack()

        create = Button(new_folder_modal,
                        text="Создать",
                        command=self.create_folder)
        create.pack()
        pass

    def create_folder(self):
        name = self.entry.get()
        self.api.create_folder(name, self.path)
        self.fill_listbox()

    def listbox_click(self):
        item = self.listbox.get('active')  # get clicked item
        folder = ''
        if item.find(self.folder) > -1:
            self.path.append(item.split(':')[1])
            self.fill_listbox()
            return
        if item == '/':
            if len(self.path) > 1:
                self.path.pop()
            self.fill_listbox()
            return
        else:
            self.file_modal(item)

    def file_modal(self, item):
        top = Toplevel(self.root)
        self.text = Text(top)
        self.text.pack()

        file = self.api.file_get_content(self.path, item)
        self.text.delete('1.0', END)
        self.text.insert(END, file.content.decode('utf-8'))

        save = Button(top, text="Сохранить", command=self.save)
        save.pack()

    def save(self):
        item = self.listbox.get('active')
        text = self.text.get("1.0", END)
        self.api.save(text, self.path, item)
        self.fill_listbox()
        pass
예제 #5
0
#                          Sæunn Elín Ragnarsdóttir
#                               Summer of 2020
#                            University of Iceland
# =============================================================================

import sqlite3
from API import Api
import datetime

# =============================================================================
# This program saves data from CoinMarketCap to a database.
# This program will be run every hour.
# =============================================================================

# The class Api from the API file
api = Api()

# The Pricing information from CoinMarketCap is fetched directly
api.readfromCMC()

# Connect to the following database file
conn = sqlite3.connect("cmcdata.db")

# A cursor is defined
c = conn.cursor()

# Date and time variable defined
datetime = datetime.datetime.now()


# The following function creates the SQLite table CMCdata
예제 #6
0
    def __init__(self):

        self.country = Api("None")
        self.country.getApi()
from API import Api
import time
import sys

passphrase = ""
key = ""
b64 = ""

url = 'https://api-public.sandbox.pro.coinbase.com'

a = Api("cbpro", passphrase=passphrase, b64=b64,
    key=key, url=url)
a.start()
try:
    while True:
        time.sleep(0.2)
        o = input("buy or sell ? ")
        if "buy" in o:
            a.buy(float(input("Which size would you buy ? ")))
        elif "sell" in o:
            a.sell(float(input("Which size would you buy ? ")))
        else:
            print ("I don't understand, please retry\n")
        time.sleep(1)
except KeyboardInterrupt:
    a.stop()
    sys.exit(0)