Esempio n. 1
0
    def sendNearPOI(self, bot, chat_id, pos):
        io = (pos['latitude'], pos['longitude'])
        distDict = {}
        db = pickledb.load('db/mensaDB.db', False)
        for key in db.getall():
            a = db.get(key)
            mensaCoord = (a['coord']['lat'], a['coord']['lon'])
            distDict[key] = vincenty(io, mensaCoord).kilometers
        MensaNearPOI = min(distDict, key=distDict.get)
        km = str(round(float(distDict[MensaNearPOI]), 4))
        prettyNearPOI = str(MensaNearPOI).title()
        if prettyNearPOI == 'Sanfrancesco':
            prettyNearPOI = 'San Francesco'
        textMensa = 'Mensa più vicina: ' + str(prettyNearPOI) + \
                    ', distanza: ' + str(km) + ' km' + \
                    '. \nPer maggiori informazioni: /' + str(MensaNearPOI)

        io = (pos['latitude'], pos['longitude'])
        distDict = {}
        db = pickledb.load('db/aulastudioDB.db', False)
        for key in db.getall():
            a = db.get(key)
            asCoord = (a['coord']['lat'], a['coord']['lon'])
            distDict[key] = vincenty(io, asCoord).kilometers
        AsNearPOI = min(distDict, key=distDict.get)
        km = str(round(float(distDict[AsNearPOI]), 4))
        prettyNearPOI = str(AsNearPOI).title()
        if prettyNearPOI == 'Viavenezia':
            prettyNearPOI = 'Via Venezia'
        elif prettyNearPOI == 'Titolivio':
            prettyNearPOI = 'Tito Livio'
        elif prettyNearPOI == 'Vbranca':
            prettyNearPOI = 'Vittore Branca'
        elif prettyNearPOI == 'Reset':
            prettyNearPOI = 'Circolo Reset'
        textAS = '\n\nAula studio più vicina: ' + str(prettyNearPOI) + \
            ', distanza: ' + str(km) + ' km' + \
            '. \nPer maggiori informazioni: /' + str(AsNearPOI)

        distDict = {}
        db = pickledb.load('db/biblioDB.db', False)
        for key in db.getall():
            a = db.get(key)
            biblioCoord = (a['coord']['lat'], a['coord']['lon'])
            distDict[key] = vincenty(io, biblioCoord).kilometers
        biblioNearPOI = min(distDict, key=distDict.get)
        km = str(round(float(distDict[biblioNearPOI]), 4))
        prettyNearPOI = db.get(biblioNearPOI)['nome']
        textBiblio = '\n\nBiblioteca più vicina: ' + str(prettyNearPOI) + \
            ', distanza: ' + str(km) + ' km' + \
            '. \nPer maggiori informazioni: /' + str(biblioNearPOI)

        text = textMensa + textAS + textBiblio
        markup = [['/' + MensaNearPOI, '/' + AsNearPOI],
                  ['/' + biblioNearPOI, '/home']]
        reply_markup = telegram.ReplyKeyboardMarkup(markup)
        bot.sendMessage(chat_id=chat_id, text=text, reply_markup=reply_markup)
Esempio n. 2
0
def init_db(db_name):
    try:
        os.remove(db_name)
    except:
        pass
    db = pickledb.load(db_name, False)
    db.dump()
Esempio n. 3
0
def signup(bot, update):
    pytrtbot.writedb(update.message.to_dict())
    userId = str(update.message.from_user.id)
    db = pickledb.load('db/users.db', False)
    try:
        if db.get(userId)['register']:
            key = update.message.text.split()[0]
            secret = update.message.text.split()[1]
            insertApiKey = {
                'apikey': key,
                'apisecret': secret,
                'register': False
            }
            db.set(userId, insertApiKey)
            db.dump()
            reply_markup = ReplyKeyboardMarkup([['/balances'], ['/home']])
            bot.sendMessage(update.message.chat_id,
                            text='User registered! Use /balances to try it',
                            reply_markup=reply_markup)
    except:
        reply_markup = ReplyKeyboardMarkup([['/register'],
                                            ['/home'],
                                            ['/help']])
        bot.sendMessage(update.message.chat_id,
                        text='You can register! Type /register ' +
                             'and follow the instructions',
                        reply_markup=reply_markup)
Esempio n. 4
0
def start(__cloudify_id, db_name='pickle', db_data={}, **kwargs):
    db_file = get_db_file_location(db_name)
    db = pickledb.load(db_file, False)
    for key, value in db_data.iteritems():
        db.set(key, value)
    db.dump()
    send_event(__cloudify_id, "10.0.0.5", "pickle db status", "state", "running")
Esempio n. 5
0
def generate_file(channel_folder):
    all_the_channels = {}
    log.info(channel_folder)
    # parser = etree.XMLParser(recover=True, encoding="utf8")
    parser = etree.XMLParser()
    db = pickledb.load('trashit.db', False)

    for channel_entries in os.listdir(channel_folder):
        target = os.path.join(channel_folder, channel_entries)
        is_xml = target.endswith('.xml')
        if is_xml:
            channel = open(target, 'r').read()
            # root = etree.parse(target, parser=parser)
            root = etree.fromstring(channel, parser)
            nodes = root.xpath('//channels/channel')
            for node in nodes:
                # the_id = node.get('xmltv_id').encode('utf8')
                the_id = HTMLParser().unescape(node.get('xmltv_id')).lower()\
                    .replace(' ', '')
                found = db.get(the_id)

                if found is None:
                    # name = HTMLParser().unescape(tostring(node).strip())
                    name = tostring(node).strip()
                    all_the_channels.update({the_id: name})
                    db.set(the_id, True)
                else:
                    log.info("%s was found, it won't be added" % the_id)
    sorted_chans = OrderedDict(sorted(all_the_channels.items(),
                                      key=lambda t: t[0]))
    return sorted_chans
Esempio n. 6
0
def generate_diff(xml_file, new_xml):
    parser = etree.XMLParser()
    new_parser = etree.XMLParser()

    xml_file_db = pickledb.load('original.db', False)

    channel = open(xml_file, 'r').read()
    new_channels = open(new_xml, 'r').read()

    root = etree.fromstring(channel, parser)
    nodes = root.xpath('//channel')

    root_new = etree.fromstring(new_channels, new_parser)
    nodes_new = root_new.xpath('//channels/channel')

    for node in nodes:
        # the_id = node.get('xmltv_id').encode('utf8')
        the_id = HTMLParser().unescape(node.get('xmltv_id')).lower()\
                .replace(' ', '')
        xml_file_db.set(the_id, True)

    for node in nodes_new:
        the_id = HTMLParser().unescape(node.get('xmltv_id')).lower()\
                .replace(' ', '')
        was_found = xml_file_db.get(the_id)
        if was_found is None:
            raw_node = tostring(node).strip()
            print "Add {} to the file".format(raw_node)
Esempio n. 7
0
    def __init__(self, login_email, login_id, login_password, logging=True):
        """
        Initialize class properties
        :param login_email: String - Login account email
        :param login_id: Int - Login account ID
        :param login_password: String - Login password
        :return: void
        """
        self.logging = logging
        self.login_email = login_email
        self.login_id = login_id
        self.login_password = login_password

        # Get cookies and access_token from external storage.
        # If external storage is empty or values expired, it will be requested from Chatwork later.
        self.storage = pickledb.load(os.path.dirname(__file__) + '/cwui.db', True)
        if self.storage.get("cwssid"):
            self.cookies["cwssid"] = self.storage.get("cwssid")
        if self.storage.get("AWSELB"):
            self.cookies["AWSELB"] = self.storage.get("AWSELB")
        if self.storage.get("access_token"):
            self.access_token = self.storage.get("access_token")

        # Request cookies and access_token from Chatwork
        if not self.cookies:
            if not self._login():
                self._log("Login failed!", 'CRITICAL')
        if not self.access_token:
            if not self._getAccessToken():
                self._log("ACCESS_TOKEN not found!", 'CRITICAL')
Esempio n. 8
0
def get_events():
   pdb = pickledb.load('movements.db', False)
   status = pdb.get('status')
   beacon = request.args.get('beacon',False,type=bool)
   device = request.args.get('device',False,type=bool)
   movement = request.args.get('movement', False, type=bool)
   if(not beacon and not device and movement and status != 0):
      send_intrusion()
      x8 = ELE8()
      x8.initial()
      x8.paint_d()
      time.sleep(5)
      x8.finalize()
      status = 0
   elif(beacon or device):
      if(not device and status != 2):
        x = commands.getoutput("sudo bash changeDNS.sh -f")
        status = 2
      elif(status != 3):
        x = commands.getoutput("sudo bash changeDNS.sh -o")
        status = 3
      else:
        status = 1
      send_entrada_salida()
      x8 = ELE8()
      x8.initial()
      x8.paint_ok()
      time.sleep(5)
      x8.finalize()
   else:
      status = 4
   pdb.set('status',status)
   pdb.dump()
   return "Yeah"
Esempio n. 9
0
 def __init__(self):
     self.MAXFIELDS=10
     self.MINFIELDS=0    
     self.sensorList=[]
     self.db = pickledb.load('movements.db', False) 
     
     self.setSTime( 0)
Esempio n. 10
0
 def oneUni(self, uniID):
     db = pickledb.load('uni.db', False)
     thisUni = db.get(uniID)
     infoUni = []
     for key in thisUni:
         infoUni.append(key)
     return {"data": infoUni}
Esempio n. 11
0
def in_db(fileName):
	dataBaseName = "pictureDatabase"
	db = pickledb.load(dataBaseName, False)
	dbKeys = db.getall()
	if fileName in dbKeys:
		return True
	else:
		return False
Esempio n. 12
0
def to_db(key, value):
	dataBaseName = "pictureDatabase"
	db = pickledb.load(dataBaseName, False)
	dbKeys = db.getall()
	if key not in dbKeys:
		print 1, key
		db.set(key, value)
		db.dump()
Esempio n. 13
0
 def __init__(self, chat_file):
     self.chat_db = pkl.load(chat_file, False)
     try:
         num = self.chat_db.llen('chats')
         logging.warning('chats in DB: %s' % num)
     except KeyError:
         self.chat_db.lcreate('chats')
         logging.warning('chat DB created')
Esempio n. 14
0
def test():
    db_name = 'pickle'
    db_data = {'key1': 'value1', 'key2': 'value2'}
    start(db_name, db_data)
    db_file = get_db_file_location(db_name)
    db = pickledb.load(db_file, False)
    print(db.get('key1'))
    print(db.get('key2'))
    print(get_db_file_location(db_name))
Esempio n. 15
0
def check_for_result(key):
    """
    Checks whether or not a key exists in our database. If it does, function returns the value, otherwise False. 
    """
    db = pickledb.load(DATABASE_NAME, False)
    k = db.get(key)
    if k == None:
        return False
    else:
        return k
Esempio n. 16
0
def register(bot, update):
    pytrtbot.writedb(update.message.to_dict())
    db = pickledb.load('db/users.db', False)
    db.set(update.message.from_user.id, REG)
    db.dump()
    reply_markup = ReplyKeyboardHide()
    bot.sendMessage(update.message.chat_id,
                    text='Send your public API Key and API ' +
                    'secret, with a space between them.',
                    reply_markup=reply_markup)
Esempio n. 17
0
def webhook_handler():
    if request.method == "POST":
        # retrieve the message in JSON and then transform it to Telegram object
        update = telegram.Update.de_json(request.get_json(force=True))
        chat_id = str(update.message.chat.id)
        text = update.message.text.encode('utf-8')
        db = pickledb.load(DBFile, False)
        custom_keyboard = [[ 'Zabbix status' ]]
        reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard)
        allchats = db.getall()
        if chat_id in allchats and db.get(chat_id) == 'valid':
            if text.lower() == 'zabbix status' or text.lower() == '/status':
                triggers = zabbix_triggers()
                haveproblems = None
                fullalerttext = 'Zabbix:\n'
                for t in triggers:
                    if int(t['value']) == 1:
                        haveproblems = True
                        alerttext=t['host'] + ' - ' + t['description']
                        if int(t['priority']) == 1:
                            fullalerttext = fullalerttext + alerttext.encode('utf-8') + ' - Information' + telegram.Emoji.SMILING_FACE_WITH_SUNGLASSES + '\n'
                        elif int(t['priority']) == 2:
                            fullalerttext = fullalerttext + alerttext.encode('utf-8') + ' - Warning' + telegram.Emoji.WORRIED_FACE + '\n'
                        elif int(t['priority']) == 3:
                            fullalerttext = fullalerttext + alerttext.encode('utf-8') + ' - Average' + telegram.Emoji.FACE_WITH_OPEN_MOUTH + '\n'
                        elif int(t['priority']) == 4:
                            fullalerttext = fullalerttext + alerttext.encode('utf-8') +  ' - High' + telegram.Emoji.FEARFUL_FACE + '\n'
                        elif int(t['priority']) == 5:
                            fullalerttext = fullalerttext + alerttext.encode('utf-8') +  ' - Disaster' + telegram.Emoji.FACE_SCREAMING_IN_FEAR + '\n'
                        else:
                            fullalerttext = fullalerttext + alerttext.encode('utf-8') + ' - Not classified' + telegram.Emoji.WINKING_FACE + '\n'
                if not haveproblems:
                    fullalerttext = fullalerttext + 'Everything is OK!' + telegram.Emoji.SMILING_FACE_WITH_SUNGLASSES
                bot.sendMessage(chat_id=chat_id, text=fullalerttext, reply_markup=reply_markup)
            elif text.lower() == 'unsubscribe' or text.lower == '/unsubscribe':
                db.rem(chat_id)
                db.dump()
                reply_markup = telegram.ReplyKeyboardHide()
                bot.sendMessage(chat_id=chat_id, text='You successfully unsubscribed!\nYou will not receive alerts from this bot.', reply_markup=reply_markup)
#            if text.lower() == '/start' or text.lower() == '/help':
            else:
                bot.sendMessage(chat_id=chat_id, text='List of bot commands:\n/status - show all alerts\n/unsubscribe - unsubscribe from this bot\n/help - list of bot commands', reply_markup=reply_markup)
        else:
            if chat_id in allchats and db.get(chat_id) == 'unauth':
                if text == ChatPassword:
                    db.set(chat_id, 'valid')
                    db.dump()
                    bot.sendMessage(chat_id=chat_id, text='You successfully authenticated. Now you will be receive alerts from zabbix.\nType /help to see all commands.', reply_markup=reply_markup)
                else:
                    bot.sendMessage(chat_id=chat_id, text='Wrong password. Please enter valid password')
            else:
                db.set(chat_id, 'unauth')
                db.dump()
                bot.sendMessage(chat_id=chat_id, text='Please enter password')
    return 'ok'
Esempio n. 18
0
def add_result(key,value):
    """
    Adds a key and value to the database-file. the function returns False if the entry already exists. Otherwise True
    """
    db = pickledb.load(DATABASE_NAME, False)
    if db.get(key) == None:
        db.set(key, value)
        db.dump()
        return True
    else:
        return False
Esempio n. 19
0
def get_from_db(angle):
    ''' get_from_db returns the value of the given key 'angle'

    Args:
        angle : the key (angle) that should be queried
    Returns:
        x (tuple) : A tuple of avrage lift force, avrage drag force, angle calculated on and download URL
    '''
    db = pickledb.load('example.db', False)
    x = db.get(str(angle))
    return x
Esempio n. 20
0
def deleteKeys(bot, update):
    pytrtbot.writedb(update.message.to_dict())
    db = pickledb.load('db/users.db', False)
    db.rem(str(update.message.from_user.id))
    db.dump()
    reply_markup = ReplyKeyboardMarkup([['/price', '/tickers'],
                                        ['/bitcoin_data'],
                                        ['/register', '/help']])
    bot.sendMessage(update.message.chat_id,
                    text='Your keys are deleted. You can use the bot anyway!',
                    reply_markup=reply_markup)
Esempio n. 21
0
 def allUni(self):
     db = pickledb.load('uni.db', False)
     uniList = db.getall()
     info = {}
     for u in uniList:
         thisUni = db.get(u)
         infoUni = []
         for key in thisUni:
             infoUni.append(key)
         info[u] = infoUni
     return info
Esempio n. 22
0
def generate_rewrites(results_path='./results', rewrite_db_path='../rewrite.db'):
    rewrites = []
    pages = [
        page.replace('.html', '') for page in os.listdir(results_path)
        if '.html' in page and len(page) == 32+5]
    rewrite_db = pickledb.load(rewrite_db_path, True)
    for page in pages:
        rewrite = {}
        rewrite['source'] = '/' + rewrite_db.get(page)
        rewrite['destination'] = '/' + page + '.html'
        rewrites.append(rewrite)
    return rewrites
Esempio n. 23
0
def replier(command):
    db = pickledb.load('db/univeronabot.pickledb', False)
    reply = db.get(command)['text']
    keyboard = db.get(command)['keyboard']
    try:
        coord = db.get(command)['coord']
        lat = coord['lat']
        lon = coord['lon']
    except:
        lat = None
        lon = None
    return reply, keyboard, lat, lon
Esempio n. 24
0
    def process_item(self, item, spider):
        #add url to list of keys/urls
        log.msg("Processing an AuthInfoItem", level = log.INFO)

        self.db_location = spider.db_name
        self.db = pickledb.load(self.db_location, False)
        self.db.lcreate("auth_urls")
        log.msg("Using db at location %s" % self.db_location, level = log.INFO)
        
        if isinstance(item, AuthInfoItem):
            if item["response_url"] not in self.db.lgetall("auth_urls"):
                self.db.ladd("auth_urls", item["response_url"])
                self.db.set(item["response_url"], dict(item))
                self.db.dump()
Esempio n. 25
0
 def reply(self, bot, update, message, command, chat_id):
     commandsDB = pickledb.load('db/commandsDB.db', False)
     pyUniPd.writedb(update.message.to_dict())
     bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)
     reply = commandsDB.get(command)['text']
     markup = commandsDB.get(command)['keyboard']
     reply_markup = telegram.ReplyKeyboardMarkup(markup)
     bot.sendMessage(chat_id=chat_id, text=reply,
                     reply_markup=reply_markup)
     if commandsDB.get(command)['coord'] is not None:
         lat = commandsDB.get(command)['coord']['lat']
         lon = commandsDB.get(command)['coord']['lon']
         bot.sendLocation(chat_id=chat_id, latitude=lat, longitude=lon)
     else:
         pass
Esempio n. 26
0
def help(bot, update):
    pytrtbot.writedb(update.message.to_dict())
    db = pickledb.load('db/users.db', False)
    userId = str(update.message.from_user.id)
    try:
        registered = not db.get(userId)['register']
    except:
        registered = False
    if registered:
        reply_markup = ReplyKeyboardMarkup([['/delete_keys'],
                                            ['/home']])
    else:
        reply_markup = ReplyKeyboardMarkup([['/home']])
    bot.sendMessage(update.message.chat_id,
                    text=pytrtbot.Help(),
                    reply_markup=reply_markup)
Esempio n. 27
0
    def __init__( self, cert, username, url, offline=False ):

        self.cert = cert
        self.username = username
        self.phab_url = url

        self.offline = offline

        if self.offline  == False:
            self.conduit = self._openConnection()

        self.phidCache = pickledb.load('phid.db', False)

        #first time init?
        if len(self.phidCache.db) == 0:
            print "First time init - making PHID db"
            self.refreshPHIDs()
Esempio n. 28
0
    def update(self, crowd_response):
        task = crowd_response.task
        workflow = task.workflow
        crowdrouter = workflow.crowdrouter
        db = pickledb.load(self.db_path, True)
        # import ipdb; ipdb.set_trace()

        #Base case - initialize any extra task keys in task_counts.
        self.refresh_stats(db, crowdrouter.workflows, task.__class__)

        #Task Counts
        method = crowd_response.crowd_request.get_method()
        self.task_counts[workflow.get_name()][task.get_name()][method] += 1

        #DB set and save.
        db.db["task_counts"] = self.task_counts
        db.dump()
Esempio n. 29
0
def check_db(angle):
    ''' check_db checks if the key 'angle' exists in the database 

    Args:
        angle : the key (angle) that should be queried
    Returns:
        True if the key exists
        False otherwise
        
    '''
    db = pickledb.load('example.db', False)
    x = db.get(str(angle))
    if x != None:
        db.dump() 
        return True
    else:
        db.dump() 
        return False
Esempio n. 30
0
def transactions(bot, update):
    pytrtbot.writedb(update.message.to_dict())
    userId = str(update.message.from_user.id)
    db = pickledb.load('db/users.db', False)
    try:
        apikey = db.get(userId)['apikey']
        apisecret = db.get(userId)['apisecret']
        markup, reply = pytrtbot.MyTransactions(apikey, apisecret)
        reply_markup = ReplyKeyboardMarkup([[markup]])
        bot.sendMessage(update.message.chat_id,
                        text=reply,
                        reply_markup=reply_markup)
    except:
        reply_markup = ReplyKeyboardMarkup([['/register'], ['/home']])
        bot.sendMessage(update.message.chat_id,
                        text='You must register! Type /register ' +
                             'and follow the instructions',
                        reply_markup=reply_markup)
Esempio n. 31
0
import pickledb

db = pickledb.load('realmp7data.db', False)


def passData(name, preferences, time, id):
    namepreftime = [name, preferences, time]
    db.set(id, namepreftime)


def returnData(id):
    return db.get(id)
Esempio n. 32
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import random
import upsidedown
import pickledb
import datetime
import config
import datetime
import calendar

welcome = pickledb.load("welcome.json", True)
left = pickledb.load("left.json", True)
rules = pickledb.load("rules.json", True)
welcomedis = pickledb.load("welcomedis.json", True)
ignorelist = pickledb.load("ignore.json", True)

def Ignore(message):
    if str(message.reply_to_message.from_user.id) in ignorelist.getall():
        ignorelist.rem(str(message.reply_to_message.from_user.id))
        return False
    else:
        ignorelist.set(str(message.reply_to_message.from_user.id), "ignore")
        return True

def GetUnixDelta(arg): # pCode now
    minutes = 0
    weeks = 0
    seconds = 0
    days = 0
    pArr = arg.split(" ")
Esempio n. 33
0
 def _open_ancdb(self):
     ancdb_path = self.repo + '/' + self.mmdb.get('ancdb_path')
     if not ancdb_path:
         print('Error: ancestor db not found. Was oxly clone run?')
         sys.exit(1)
     return pickledb.load(ancdb_path, 'False')
Esempio n. 34
0
        else:
            error_str = json.dumps(error_json)
    except:
        error_str = str(res.__dict__)
    return error_str


# setup logger and status
if not os.path.exists(config.LOGS_DIRECTORY):
    os.makedirs(config.LOGS_DIRECTORY)
error_logger = setup_logger('error_logger',
                            '/'.join([config.LOGS_DIRECTORY,
                                      'error.log']), logging.ERROR)
info_logger = setup_logger('info_logger',
                           '/'.join([config.LOGS_DIRECTORY, 'logs.log']))
status = pickledb.load('/'.join([config.LOGS_DIRECTORY, 'status.json']), True)


def infinite_loop(sleep_time=15):
    print("Service Running...")
    while True:
        try:
            main()
            time.sleep(sleep_time)
        except BaseException as e:
            print(e)


if __name__ == "__main__":
    infinite_loop()
Esempio n. 35
0
class Octopart:
    db = pickledb.load("octopart.db", False)

    def __init__(self, key='&apikey=e2c08378'):
        self.key = key

    def Dump(self):
        Octopart.db.dump()

    def QueryWeb(self, mpns):
        if len(mpns) > 20:
            print "Octopart does not support more than 20 queries at a time for free"
            return

        queries = [{'mpn': l, 'reference': l} for l in mpns]

        url = 'http://octopart.com/api/v3/parts/match?queries=%s' % urllib.quote(
            json.dumps(queries))
        url += self.key
        data = urllib.urlopen(url).read()
        response = json.loads(data)

        results = response['results']

        for result in results:
            Octopart.db.set(result['reference'], result)

        self.Dump()

    def DebugPrint(self, mpn):
        def rec(o, indent):
            if type(o) is dict:
                for k, v in o.iteritems():
                    if type(v) is dict or type(v) is list:
                        print indent * ' ', k, ':'
                        rec(v, indent + 2)
                    else:
                        print indent * ' ', k, ':', v
            elif type(o) is list:
                for v in o:
                    rec(v, indent + 2)
            else:
                print indent * ' ', o

        v = self.db.get(mpn)
        if v == None:
            print "MPN", mpn, "does not exist in DB"
            for k in self.db.getall():
                print k
            return

        rec(v, 0)

        return v

    def Quotes(self, mpn, quantity):

        ##print "Quote for",mpn,quantity
        quotes = []
        if mpn in overrides:
            print "WARNING: Using override for", mpn
            quotes.extend(overrides[mpn])
            return quotes
        else:
            v = self.db.get(mpn)

        if v == None:
            ## Add any special quotes
            if mpn in special:
                quotes.extend(special[mpn])
            ##print "MPN",mpn,"does not exist in DB"
            return quotes

        items = v['items']

        for item in items:
            manufacturer = item['manufacturer']['name']
            offers = item['offers']
            for offer in offers:
                ## Only accept if quotes are in USD
                if 'USD' not in offer['prices'].keys(): continue
                ## Only accept if enough parts are in stock
                if offer['in_stock_quantity'] < quantity: continue
                price = None
                for price_tuple in offer['prices']['USD']:
                    # Find correct price break
                    if price_tuple[0] > quantity: break
                    price = Decimal(price_tuple[1])
                ## Only accept if a valid price exists
                if not price: continue
                quote = Quote(price, offer['seller']['name'],
                              offer['seller']['homepage_url'], manufacturer,
                              offer['sku'], mpn)
                quotes.append(quote)

        ## Add any special quotes
        if mpn in special:
            quotes.extend(special[mpn])

        return quotes
Esempio n. 36
0
def lazy(fn):
    global bshipdb
    if not bshipdb:
        bshipdb = pickledb.load('bshipdb.db', True)
    return fn
Esempio n. 37
0
 def __init__(self, bot):
     self.bot = bot
     self.cooldowns = {}
     self.xp_db = pickledb.load("data\\xp.db", True)
     self.vault_db = pickledb.load("data\\vault.db", True)
Esempio n. 38
0
#!/usr/bin/env python

import sys
import serial
import json
import pickledb

(me, device, command) = sys.argv

db = pickledb.load('example.db', False)

with serial.Serial('/dev/cu.SLAB_USBtoUART', 115200) as ser:
    key = "%s/%s" % (device, command)
    cmd = db.get(key)
    cmd['act'] = 'tra'
    ser.write(bytes(json.dumps(cmd, separators=(',', ':')), 'US-ASCII'))
    ser.write(b'\n')
    line = ser.readline()  # read a '\n' terminated line
    resp = json.loads(line)
    if resp["ok"]:
        print("OK")
    else:
        print(resp["err"])
        exit(1)
Esempio n. 39
0
def openDb(dbpath):
    db = pickledb.load(dbpath, True)
    return db
    #port1 = port1 + 1

else:
    port1 = port1 + 5
    print("************ I am Non-Primary Replica (%d) ************" % (port1))
    #    for replica in [replica2]:     #, replica2, replica3, replica4]:
    print("Esatablishing connection to Primary replica with port number: %d" %
          (port1))
    thread_c = threading.Thread(target=non_primary_func, args=(port1, ))
    thread_c.start()

host = ''
port = int(sys.argv[1])  #Port number is my lucky number :-)
BUFSIZE = 1024  #Max size handling per line of data from the client
#consistency = sys.argv[2]
r1 = pickledb.load("replica", False)

print("Running at port number:%d to communicate to client" % (port))

s = socket.socket(
    socket.AF_INET, socket.SOCK_STREAM
)  # Providing required deatils for the socket function to connect to client
s.bind((host, port))
print("Server started on port: %s" % port)
s.listen(1)
print("Now listening...\n")
data_1 = {}
time_1 = {}

conn, addr = s.accept()  # Accept connection from the client
while True:
Esempio n. 41
0
File: rss.py Progetto: shelldi/robo
# Get it by creating a bot on https://t.me/botfather
log_channel = "-1001336920806"  # Telegram Channel ID where the bot is added and have write permission. You can use group ID too.
check_interval = 5  # Check Interval in seconds.
max_instances = 5  # Max parallel instance to be used.
if os.environ.get(
        "ENV"
):  # Add a ENV in Environment Variables if you wanna configure the bot via env vars.
    api_id = os.environ.get("APP_ID")
    api_hash = os.environ.get("API_HASH")
    feed_url = os.environ.get("FEED_URL")
    session_name = os.environ.get("SESSION_NAME")
    log_channel = int(os.environ.get("LOG_CHANNEL", None))
    check_interval = int(os.environ.get("INTERVAL", 30))
    max_instances = int(os.environ.get("MAX_INSTANCES", 5))

db = pickledb.load('rss.db', True)
if db.get("feed_url") == None:
    db.set("feed_url", "*")
app = Client(session_name=session_name, api_id=api_id, api_hash=api_hash)


def check_feed():
    FEED = feedparser.parse(feed_url)
    entry = FEED.entries[0]
    if entry.id != db.get("feed_url"):

        # ↓ Edit this message as your needs.
        message = f"{entry.link}"

        try:
            app.send_message(log_channel, message)
Esempio n. 42
0
        for url in self.urls:
            driver = self.browser.get(url)
            print driver.current_url
            for joke_element in driver.find('#main article').find('.row'):
                try:
                    vote = joke_element.find('.votes').text.split()
                    if int(vote[1]) >= 200:
                        jokes.append(joke_element.find('.joke').text)
                except AttributeError:
                    print "I am not an element."
        print jokes
        self.db.set('jokes', jokes)
        print '*'*100
        print 'Updated!'
        self.browser.close()
        self.display.stop()

    def get_urls(self):
        default_url = 'http://www.osvigaristas.com.br/piadas/curtas/'
        urls = [default_url + 'pagina{}.html'.format(i)
                for i in range(2, 51)]
        urls.append(default_url)
        return urls

    def get_jokes(self):
        return self.db.get('jokes')


if __name__ == '__main__':
    Joke(db=pickledb.load(os.environ['HOME'] + '/douglas_db/douglas.db', True)).run()
Esempio n. 43
0
import facebook


def cache_events(token, userid="10156265228397361"):
    token = "EAAcN8pRZBfnQBAKiFZAzFifP1jSV7gsVRErt3milnhMO9H2EgZBBxyciwH1z4MhqygtSo3OQVO1QG6RkBlbSdZCsg4umX7m7UvLPonZAk8q8GEfjjNhF9S4ZB8Ksl7H5KKOqCAdOr14xpxhmfKFUvBibMzD21RCAfqQTQnZAZBZAHSB8sh4QZCr9A3eybYPHSXZCdvyzOJs3DK3ZAwZDZD"
    graph = facebook.GraphAPI(access_token=token, version="2.8")
    rez = graph.get_all_connections(id=userid, connection_name='events')
    print(rez)
    c = 0
    for event in rez:
        c += 1
        print(event)
        break
    print(c)  # 223

    exit()


# https://github.com/patx/pickledb
import pickledb

db = pickledb.load('fbevents.db', False)

for event in rez:
    db.set(event["id"], event)

db.dump()

db = pickledb.load('fbevents.db', False)
print(len(db.getall()))
Esempio n. 44
0
from netcontroller import NetController
from flask import Flask
from flask_mail import Mail, Message
import pickledb
import json

def render_template(argss,filename):
    htmlfile = open('templates/'+filename,'r').read()
    for me in argss:
        htmlfile = htmlfile.replace('%'+me+'%',argss[me])
    return htmlfile

db = pickledb.load('log.db', False)
net = NetController()
net.load_config('config.json')

app = Flask(__name__)
app.debug = True

try:
    conf = open('email.json').read()
    pass
except Exception as e:
    print('Can not open config file: '+str(e))
    conf = ''
    pass

if conf != '':
    jsconf = json.loads(conf)
    app.config['MAIL_SERVER'] = jsconf["smtp"]
    app.config['MAIL_PORT'] = int(jsconf["port"])
Esempio n. 45
0
import pickledb
import subprocess, re, os, sys


def shcmd(cmd):
    subprocess.call(cmd, shell=True)


if __name__ == '__main__':
    pwd = os.getcwd()
    db_name = sys.argv[1]
    db_dir = sys.argv[2]

    # make protodb
    cmd = './match --build %s' % db_dir
    print cmd
    shcmd(cmd)

    # make pickledb
    pickdb = pickledb.load(db_name + '.pickle', False)
    imgs = os.listdir(db_dir)
    for i in imgs:
        if i.endswith('.jpg'):
            # remove extension and tokenize
            data = os.path.splitext(i)[0].split('-')
            text = ' '.join(data)
            print text
            pickdb.set(i, data)

    pickdb.dump()
Esempio n. 46
0
 def get_template_name(self):
     template_db = pickledb.load(
         'static/user/public/template_view/template_view.db',
         False,
         sig=False)
     return template_db.dkeys(self.username)
Esempio n. 47
0
def get_config(key, dbfile):
    pdb = pickledb.load(dbfile, False)
    config = pdb.dgetall(key)
    return config
Esempio n. 48
0
 def get_global_sending_id(self):
     gsid_db = pickledb.load('static/user/public/template_view/gsid.db',
                             False,
                             sig=False)
     return gsid_db.get(self.username)
 def __init__(self, news_file):
     self.news_db = pkl.load(news_file, False)
     if not self.news_db.get('link'):
         self.news_db.set('link', 'empty')
     if not self.news_db.get('text'):
         self.news_db.set('text', 'empty')
Esempio n. 50
0
def load_and_migrate(db_file, pickle_migrator_class):
    # Set force save to false, because we don't want to save when we have partially completed a
    # migration.
    db = pickledb.load(db_file, False)
    pickle_migrator_class(db).migrate()
    return db
Esempio n. 51
0
# classes: history, current, forecast, parsing JSON,
import sys
import urllib.request, urllib.parse, urllib.error
import json
import ssl
import pickledb
import os
import anotherOutput
from model import weather_model
from model import database

arguments = str(sys.argv)
location = sys.argv[1][3:]
api_key = os.environ.get('api_key')
db = pickledb.load('history.db', False)


class Weather:
    def __init__(self, outputClass, databaseClass):
        self.location = location
        self.api_key = api_key
        self.output = outputClass
        self.database = databaseClass

    def current(self):
        self.serviceurl = 'http://api.openweathermap.org/data/2.5/weather?'
        self.url = self.serviceurl + 'q=' + self.location + '&APPID=' + self.api_key
        self.output.print('Retrieveing', self.url)
        self.uh = urllib.request.urlopen(self.url)
        self.data = self.uh.read().decode()
        try:
Esempio n. 52
0
    def __init__(self, App):
        super(MainWindow, self).__init__(title="Counter",
                                         application=App,
                                         decorated=True,
                                         name="csswindow")
        #self.set_default_size(280, 180)
        self.set_border_width(10)

        try:
            self.set_icon_from_file("ortealicon512.png")
            print("Icon loaded successfully")
        except Exception as e:
            print("Failed loading Icon")
            print(e.message)

        self.db = pickledb.load('pycounter.db', False)
        savedprev = self.db.get('previous')
        self.count = int(savedprev)
        print("Database loaded successfully")

        #print("Starting creating vbox")
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(vbox)

        self.countLabel = Gtk.Label(label=self.count)
        self.countLabel.set_name('cntlab')
        vbox.pack_start(self.countLabel, True, True, 0)

        incbutton = Gtk.Button.new_with_label("Increase")
        incbutton.set_name('incbut')
        incbutton.connect("clicked", self.increase)
        vbox.pack_start(incbutton, True, True, 0)

        decbutton = Gtk.Button.new_with_label("Decrease")
        decbutton.connect("clicked", self.decrease)
        vbox.pack_start(decbutton, True, True, 0)

        resetbutton = Gtk.Button.new_with_label("Reset")
        resetbutton.set_name('resetbut')
        resetbutton.connect("clicked", self.resett)
        vbox.pack_start(resetbutton, True, True, 0)

        exitbutton = Gtk.Button.new_with_label("Exit")
        exitbutton.set_name('exitbut')
        exitbutton.connect("clicked", self.exitt)
        vbox.pack_start(exitbutton, True, True, 0)

        style_provider = Gtk.CssProvider()

        css = """
        

        #incbut {
            background-color: blue;
            color: #306754;
  	    font: 22px "Comic Sans";
        }
        
        #resetbut {
            background-color: red;
            color: #C24641;
  	    
        }
               
	#cntlab {
 	    font: 50px Sans;
 	    color: #25383C;
	}
        """
        style_provider.load_from_data(bytes(css.encode()))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        print("GUI creating done")
Esempio n. 53
0
 def _hash2rev(self, filepath, hash):
     hrdb = pickledb.load(self._get_pname_hrdbpath(filepath), 'False')
     return hrdb.get(hash)
Esempio n. 54
0
def main():
    arguments = docopt(__doc__, version="ThreatPlaybook Client v 1.0.0")
    if arguments.get('configure'):
        configure_server()
    if arguments.get('init'):
        if arguments.get('<projectname>'):
            create_project(arguments.get('<projectname>'))
        else:
            print(bad("There seems to be NO Project Name"))
    if arguments.get('create'):
        if arguments.get('--file'):
            if path.isfile(arguments.get('--file')):
                if path.splitext(arguments.get('--file'))[1] == '.yaml':
                    full_path = arguments.get('--file')
                    print(full_path)
                    case_content = yaml.safe_load(open(full_path, 'r').read())
                    parse_spec_file(case_content)
        elif arguments.get('--dir'):
            if path.isdir(arguments.get('--dir')):
                full_dir_path = arguments.get('--dir')
                file_list = glob(full_dir_path + "*.yaml")
                if file_list:
                    for single in file_list:
                        with open(single, 'r') as yfile:
                            dir_case_content = yaml.safe_load(yfile.read())
                            parse_spec_file(dir_case_content)
                else:
                    print(bold(red("No files found in path")))
        else:
            print(bold(red("Unrecognized Option. Exiting...")))
            exit(1)
    if arguments.get('get'):
        if arguments.get('--json'):
            get_json_var = True
        else:
            get_json_var = False

        name_val = None
        if arguments.get('--name'):
            name_val = arguments.get('--name')

        if arguments.get('--table'):
            table_var = True
        else:
            table_var = False

        if arguments.get('feature'):
            if get_json_var and name_val:
                get_user_stories(nameval=name_val)
            elif get_json_var and not name_val and not table_var:
                get_user_stories()
            elif name_val and table_var:
                table_dict = get_user_stories(nameval=name_val, table=True)
                abuser_story_string = '\n'.join(
                    pyjq.all('.data.userStoryByName.abuses[] | .shortName',
                             table_dict))
                threat_model_strings = '\n'.join(
                    pyjq.all('.data.userStoryByName.abuses[].models[] | .name',
                             table_dict))
                feature_short_name = pyjq.first(
                    '.data.userStoryByName.shortName', table_dict)
                print(
                    tabulate([[
                        "Feature/User Story", "Abuser Story Names",
                        "Threat Scenarios"
                    ],
                              [
                                  feature_short_name, abuser_story_string,
                                  threat_model_strings
                              ]],
                             headers="firstrow",
                             tablefmt="fancy_grid"))
            elif table_var and not get_json_var and not name_val:
                all_table_dict = get_user_stories(table=True)
                feature_list = []
                abuser_story_list = []
                threat_model_list = []
                for single_table_item in all_table_dict['data']['userStories']:
                    fshort = single_table_item['shortName']
                    feature_list.append(fshort)
                    abuser_story_string = '\n'.join(
                        pyjq.all('.abuses[] | .shortName', single_table_item))
                    abuser_story_list.append(abuser_story_string)
                    threat_model_strings = '\n'.join(
                        pyjq.all('.abuses[].models[] | .name',
                                 single_table_item))
                    threat_model_list.append(threat_model_strings)

                table_dict = {
                    "Feature/User Story": feature_list,
                    "Abuser Stories": abuser_story_list,
                    "Threat Scenarios": threat_model_list
                }

                print(
                    tabulate(table_dict, headers="keys",
                             tablefmt="fancy_grid"))

        else:
            print(bold(red("Unknown Option")))
            exit(1)

    if arguments.get('login'):
        if verify_host_port():
            email = input("Please enter your email: ")
            password = getpass('Please enter your password: '******'.cred', False)
            login_url = "{}:{}/login".format(db.get('host'), db.get('port'))
            r = requests.post(login_url,
                              json={
                                  'email': email,
                                  'password': password
                              })
            if r.status_code == 200 and 'token' in r.json():
                print(good("Successfully logged in"))
                db.set('token', r.json()['token'])
                db.dump()
            else:
                print(bold(red("Invalid credentials")))

        else:
            print(
                bold(
                    red("No host and port configured for API. Please run `configure` first"
                        )))

    if arguments.get('set'):
        if arguments.get('project'):
            if arguments.get('<project_name>'):
                project_name = arguments.get('<project_name>')
                query = """
                query {
                  projectByName(name: "%s") {
                    name
                  }
                }
                """ % project_name
                res = _make_request(query)
                if res:
                    if 'data' in res:
                        db = pickledb.load('.cred', False)
                        db.set('project', project_name)
                        db.dump()
                        print(
                            good("Project {} has been set successfully".format(
                                project_name)))
                    else:
                        print(bad(res))

    if arguments.get('change-password'):
        if verify_host_port():
            db = pickledb.load('.cred', False)
            email = input("Email: ")
            old_password = getpass("Enter old/default password: "******"Enter new password: "******"Verify new password: "******"{}:{}/change-password".format(db.get('host'),
                                                     db.get('port'))
            pass_req = requests.post(baseUrl,
                                     json={
                                         "email": email,
                                         "old_password": old_password,
                                         "new_password": new_password,
                                         "verify_password": verify_password
                                     })
            if pass_req.status_code == 200:
                if 'success' in pass_req.json():
                    print(
                        good(
                            "Password for user changed successfully. Please login"
                        ))

    if arguments.get('get-scans'):
        if verify_host_port():
            get_all_scans = """
            query {
              scans {
                name
                synced
              }
            }
            """
            scan_resp = _make_request(get_all_scans)
            if scan_resp:
                if 'data' in scan_resp:
                    print(json.dumps(scan_resp, indent=2, sort_keys=True))
        else:
            print(
                bad("ERROR: There seems to be no host configured or you you seem to be logged out"
                    ))
Esempio n. 55
0
def create_project(project_name):
    """
    This function does the following:
    * Creates the Project in the TP Server and receives success message
    * Creates boilerplate directories in the current directory
    * Initializes the .cred file in the project directory
    * Sets the cred file with project name information
    :param project_name:
    :return:
    """
    print("in init method")
    db = pickledb.load('.cred', False)
    if not verify_host_port():
        print(
            bad("There's no host and port configured. Please run the `playbook configure` option first."
                ))
        exit(1)
    else:
        if verify_project():
            project_input = input(
                "There's already a project here. Are you sure you want to re-initialize? It will overwrite existing project info "
            )
            if any(project_input == word for word in ['no', 'n', 'N', 'NO']):
                print(
                    info(
                        "Project will not be overwritten. Current action ignored"
                    ))
            else:
                if ' ' in project_name:
                    project_name = project_name.replace(' ', '_').lower()
                else:
                    project_name = project_name.lower()

                create_project_query = """
                    mutation {
                      createProject(name: "%s") {
                        project {
                          name
                        }
                      }
                    }
                """ % project_name

                res = _make_request(create_project_query)
                print(res)
                try:
                    cleaned_response = utils.validate_project_response(res)
                    if cleaned_response:
                        db.set('project', project_name)
                        db.dump()
                        print(
                            good("Project: {} successfully created in API".
                                 format(project_name)))
                        # create boilerplate directories
                        list_of_directories = ["cases"]
                        for dir in list_of_directories:
                            if not path.exists(dir):
                                makedirs(dir)
                        print(
                            good("Boilerplate directories `cases` generated"))
                    else:
                        print(bad(res))
                except Exception as e:
                    print(bad(e.message))
        else:
            if ' ' in project_name:
                project_name = project_name.replace(' ', '_').lower()
            else:
                project_name = project_name.lower()

            create_project_query = """
                mutation {
                  createProject(name: "%s") {
                    project {
                      name
                    }
                  }
                }
            """ % project_name

            res = _make_request(create_project_query)
            print(res)
            try:
                cleaned_response = utils.validate_project_response(res)
                if cleaned_response:
                    db.set('project', project_name)
                    db.dump()
                    print(
                        good("Project: {} successfully created in API".format(
                            project_name)))
                    # create boilerplate directories
                    list_of_directories = ["cases"]
                    for dir in list_of_directories:
                        if not path.exists(dir):
                            makedirs(dir)
                    print(good("Boilerplate directories `cases` generated"))
                else:
                    print(bad(res))
            except Exception as e:
                print(bad(e.message))
Esempio n. 56
0
 def give_apples(self, id, new_apples):
     db = pickledb.load('appledb', False)
     existing_apples = db.get(str(id))
     total_apples = existing_apples + new_apples
     db.set(str(id), total_apples)
     db.dump()
Esempio n. 57
0
 def get_apples(self, id):
     db = pickledb.load('appledb', False)
     existing_apples = db.get(str(id))
     db.dump()
     return existing_apples
Esempio n. 58
0
    "You can use _$username_ and _$title_ as placeholders when setting"
    " messages. [HTML formatting]"
    "(https://core.telegram.org/bots/api#formatting-options) "
    "is also supported.\n")
"""
Create database object
Database schema:
<chat_id> -> welcome message
<chat_id>_bye -> goodbye message
<chat_id>_adm -> user id of the user who invited the bot
<chat_id>_lck -> boolean if the bot is locked or unlocked
<chat_id>_quiet -> boolean if the bot is quieted
chats -> list of chat ids where the bot has received messages in.
"""
# Create database object
db = pickledb.load("bot.db", True)

if not db.get("chats"):
    db.set("chats", [])

# Set up logging
root = logging.getLogger()
root.setLevel(logging.INFO)

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

logger = logging.getLogger(__name__)

hellos = [
Esempio n. 59
0
import pickledb
import glob

for name in glob.glob('data/*.db'):
    print(f'\n{name}'.replace('data/', '').replace('.db', ''))
    db = pickledb.load(name, False)
    for x in db.getall():
        print(x, db.get(x))
Esempio n. 60
0
 async def count(self, ctx):
     """------ tells you how many apples you have"""
     db = pickledb.load('appledb', False)
     apple_count = db.get(str(ctx.author.id))
     await ctx.send(f"you've got {str(apple_count)} apples!")
     db.dump()