Exemplo n.º 1
0
    def __init__(self):
        dbserver = os.environ['DB_SERVER']
        dbname = os.environ['DB_NAME']
        dbuser = os.environ['DB_USER']
        dbpass = os.environ['DB_PASS']

        con_str = pymongo.MongoClient('mongodb://{}:{}@{}/{}'.format(
            dbuser, dbpass, dbserver, dbname))
        db = dbname
        col_freebooks = 'freebooks'
        col_logs = 'logs'

        freebooks = Database(con_str, db, col_freebooks)
        logs = Database(con_str, db, col_logs)
        today = datetime.utcnow()
Exemplo n.º 2
0
 def setUpClass(cls):
     cls.db = Database("unit_test.db")
     cls.db.execute("""CREATE TABLE test(
             id   INTEGER PRIMARY KEY,
             name TEXT,
             age  INTEGER)""")
     cls.rows = [{
         "id": 1,
         "name": "dog",
         "age": 10
     }, {
         "id": 2,
         "name": "cat",
         "age": 20
     }, {
         "id": 3,
         "name": "man",
         "age": 30
     }, {
         "id": 4,
         "name": "rat",
         "age": None
     }]
     for row in cls.rows:
         cls.db.execute("INSERT INTO test(name, age) VALUES(?, ?)",
                        row["name"], row["age"])
     cls.table = IterableTable("unit_test.db", "test")
Exemplo n.º 3
0
 def setUpClass(cls):
     cls.db = Database("unit_test.db")
     cls.rows = [{
         "id": 1,
         "name": "dog",
         "age": 10
     }, {
         "id": 2,
         "name": "cat",
         "age": 20
     }, {
         "id": 3,
         "name": "man",
         "age": 30
     }, {
         "id": 4,
         "name": "rat",
         "age": None
     }]
     cls.maxDiff = None
Exemplo n.º 4
0
class IterableTable:
    """
    Turns a database table into an iterable.

    """
    def __init__(self, dbname, table):
        self.dbname = dbname
        self._db = Database(self.dbname)
        self.table = table

    def __repr__(self):
        return "{0}({1}, {2})".format(self.__class__.__name__, self.dbname,
                                      self.table)

    def __str__(self):
        return ("{0}\n"
                "Database filename: {1}\n"
                "Table-iterable: {2}\n".format(self.__class__.__name__,
                                               self.dbname, self.table))

    def exists_table(self):
        return self._db.exists_table(self.table)

    def __getitem__(self, item):
        if self.exists_table:
            statement = "SELECT * FROM {0} LIMIT ?, 1".format(self.table)
            self._db.cur.execute(statement, (item, ))
            row = self._db.cur.fetchone()
            if row is not None:
                return dict(row)
            raise StopIteration

    def take(self, n):
        try:
            return [self.__getitem__(i) for i in range(0, n)]
        except StopIteration as exc:
            raise IndexError("IterableTable index out of range") from exc

    def head(self):
        return self.take(1)
Exemplo n.º 5
0
 def __init__(self, dbname, table):
     self.dbname = dbname
     self._db = Database(self.dbname)
     self.table = table
Exemplo n.º 6
0
from os import system
import sqlite3
from dbase import Database

from active import *

if sys.platform in ['Windows', 'win32', 'cygwin']:
    import win32gui
    import uiautomation as auto
elif sys.platform in ['Mac', 'darwin', 'os2', 'os2emx']:
    from AppKit import NSWorkspace
    from Foundation import *
elif sys.platform in ['linux', 'linux2']:
    import linux as l

db = Database('saved.db')
active_window_name = ""
activity_name = ""
start_time = datetime.datetime.now()
first_time = True


def url_to_name(url):
    string_list = url.split('/')
    return string_list[2]


def get_active_window():
    _active_window_name = None
    if sys.platform in ['Windows', 'win32', 'cygwin']:
        window = win32gui.GetForegroundWindow()
Exemplo n.º 7
0
from scrap import Scrap
from dbase import Database
from datetime import datetime

dbserver = os.environ['DB_SERVER']
dbname = os.environ['DB_NAME']
dbuser = os.environ['DB_USER']
dbpass = os.environ['DB_PASS']
con_str = pymongo.MongoClient('mongodb://{}:{}@{}/{}'.format(dbuser,dbpass,dbserver,dbname))
db = dbname
col_freebooks = 'freebooks'
col_logs = 'logs'
freebooks = Database(con_str, db, col_freebooks)
logs = Database(con_str, db, col_logs)
today = datetime.utcnow()

if freebooks.find_record({"date": today.strftime("%Y-%m-%d")}):
    result = logs.insert_record({"date": today , "event": "record already in the database, skipping"})
    print('record already exists')
else:
    document = Scrap().get(url)
    result = freebooks.insert_record(document.json())
    result = logs.insert_record({"date": today , "event": "new record added to database"})
    print('new record added')

import json
import sqlite3
import urllib.request as request
from tkinter import *
from tkinter import messagebox

import requests
from PIL import Image, ImageTk
from autocompletebox import Combobox_Autocomplete
from dbase import Database
from save import Savebase

#######################################################################################################################
sdb = Savebase('saved.db')
db = Database('store.db')

with request.urlopen('https://rsbuddy.com/exchange/summary.json') as response:
    if response.getcode() == 200:
        source = response.read()
        data = json.loads(source)
        with open('rs_items.json', 'w') as f:
            json.dump(data, f, indent=4, sort_keys=True)
    else:
        print('Error')

filename = 'rs_items.json'
with open(filename) as f:
    alldicts = json.load(f)

names = []