def setUp(self): yield initDB(self) self.user = yield User(first_name="First", last_name="Last", age=10).save() self.avatar = yield Avatar(name="an avatar name", user_id=self.user.id).save() self.picture = yield Picture(name="a pic", size=10, user_id=self.user.id).save() self.favcolor = yield FavoriteColor(name="blue").save() self.boy = yield Boy(name="Robert").save() self.girl = yield Girl(name="Susan").save() self.config = Registry.getConfig()
def setUp(self): yield initDB(self) self.user = yield User(first_name="First", last_name="Last", age=10).save() self.avatar = yield Avatar(name="an avatar name", user_id=self.user.id).save() self.picture = yield Picture(name="a pic", size=10, user_id=self.user.id).save() self.dbconfig = Registry.getConfig()
def save(): print 'Crawler is running' pool = ThreadPool() proxies = pool.map(check, crawl()) pool.close() pool.join() db = initDB() for proxy in proxies: if proxy is not None: try: db.execute("insert into proxy (ip,port) values (?,?);", [proxy['ip'], proxy['port']]) db.commit() except sqlite3.Error: pass db.close()
def setUp(self): yield initDB(self) self.user = yield User(first_name="First", last_name="Last", age=10).save()
def setUp(self): yield initDB(self) self.config = Registry.getConfig()
async def on_message(client, message): global conn, c try: ignored = True now = datetime.now() #ligne = [now.year,now.month,now.day,now.hour,now.minute,now.second,str(message.author),str(message.channel.id),message.content] #c.execute("INSERT INTO logs VALUES (?,?,?,?,?,?,?,?,?)",ligne) #(annee, mois, jour, heure, minute, seconde, auteur, salon, message) #c.execute("INSERT INTO logs(annee, mois, jour, heure, minute, seconde, auteur, salon, message) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)",ligne) #conn.commit() # on ne veut pas (encore) que le bot se reponde a lui meme if (message.author == client.user or message.author.bot): # On stocke les messages envoyés par le bot, notamment pour éviter les doublons à 22h22 ligne = [ now.year, now.month, now.day, now.hour, now.minute, now.second, str(message.author), str(message.channel.id), message.content ] c.execute( "INSERT INTO logs(annee, mois, jour, heure, minute, seconde, auteur, salon, message) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)", ligne) conn.commit() return if doitEtreIgnore(str(message.channel.id)): print("Message posté dans un salon ignoré.") ignored = True #print(emoji.remove_emojis(message.content)) elif str(message.channel.id) == CHANNEL_22H22_ID: if now.hour != int(hour22h22[:2]) or now.minute != int( hour22h22[3:]): print(now.hour, ":", now.minute, " != ", hour22h22[:2], ":", hour22h22[3:]) await message.delete() ignored = False elif message.content.lower().startswith('.ignorechannel') and str( message.author.id) == OWNERID: ajouterSalonAignorer(message.content[14:]) await message.channel.send( 'Salon ajouté à la liste des salons à ignorer.') ignored = False elif message.content.lower().startswith( '.showignoredchannels') and str( message.author.id) == OWNERID: await message.channel.send(afficherSalonsIgnores(client)) ignored = False elif (message.content.startswith('.ninja')): msgSent = await message.channel.send("~ninja~") await msgSent.delete() if (peutSupprimer(message.channel)): await message.delete() print("Message supprimé") ignored = False elif ((str(message.author.id) == OWNERID) and message.content.startswith('.ecrire')): messageAenvoyer = message.content[7:] if (peutSupprimer(message.channel)): await message.delete() print("Envoi d'un message : ", messageAenvoyer) await message.channel.send(messageAenvoyer) ignored = False elif ((str(message.author.id) == OWNERID) and message.content.startswith('.exec') and (str(message.author.id) == OWNERID)): command = message.content[6:] print("Execution du code : ", message.content[6:]) exec(command) ignored = False elif (message.content.startswith('.help')): print('Demande de help par : {0.author.mention}. '.format( message)) await message.channel.send(utils.help()) ignored = False elif (message.content.startswith('.version')): print('Demande de version par : {0.author.mention}. '.format( message)) await message.channel.send(utils.version()) ignored = False elif ( (" tg " in message.content.lower() or " tg" in message.content.lower() or "tg " in message.content.lower() or message.content.lower() == "tg") and str(message.channel.id)): await message.channel.send(utils.tg()) ignored = False elif ("ping" in message.content.lower() and not emoji.message_contains_emoji_with_ping( message.content.lower()) and str(message.channel.id)): await message.channel.send("pong") ignored = False elif ((":weshalors:" in message.content.lower()) or ("wesh alors" in message.content.lower())): msg = 'Wesh alors' + ' {0.author.mention} !'.format(message) await message.channel.send(msg) ignored = False elif ((str(message.author.id) == OWNERID) and (message.content.startswith('.close') or message.content.startswith('.stop') or message.content.startswith('.logout'))): conn.commit() conn.close() # a changer pour fonctionner avec postgresql #fichierAtransmettre = discord.File('discord.db') #await message.channel.send("Le bot va s'arreter. Voila les logs :",file=fichierAtransmettre) await message.channel.send("Au revoir :)") await client.close() ignored = False elif (client.user.mentioned_in(message) and not message.mention_everyone): await message.channel.send(pleinDetoiles) ignored = False if (ignored): print("Message ignored :") print("Id du channel : ", message.channel.id) print("Auteur : ", message.author.name, " (", message.author.id, ")") print("Message : ", message.content) except psycopg2.DatabaseError as databaseError: conn, c = utils.initDB() raise Exception( 'Connexion avec la base de données interrompue. Reconnexion effectuée.' ) except Exception as exception: print(exception) user = await client.fetch_user(OWNERID) await user.send(exception)
from threading import Thread, Event from datetime import datetime import asyncio import schedule import psycopg2 import utils import emoji OWNERID = os.environ['OWNERID'] CHANNEL_22H22_ID = os.environ['CHANNEL_22H22_ID'] LOOP = asyncio.new_event_loop() asyncio.set_event_loop(LOOP) conn, c = utils.initDB() # pleinDetoiles = "°˖✧◝(⁰▿⁰)◜✧˖°" pleinDetoiles = "Oui ?" msg22h22 = "Il est 22h22, c'est parti ! Déchainez vous !" msg22h23 = "Et c'est fini pour aujourd'hui ! A demain !" summer_time = bool(os.environ['summer_time']) est_22h22 = False if summer_time: hour22h22 = "20:22" hour22h23 = "20:23" else: hour22h22 = "21:22"
default=3) parser.add_argument('--virtual', action='store_true', help='Disable card reader') args = parser.parse_args() print('Args parsed:', args) if __name__ == '__main__': # Initialize webcam before loading every other module cap = cv2.VideoCapture(0) ret, _ = cap.read() if not ret: raise RuntimeError('Video capture was unsuccessful.') initDB('/home/botoscs/sam/utils/db.conf') KNOWN_DB = {'emb': Tensor(0, 128), 'id': []} CARD2NAME = getCard2Name() if args.database is not None: KNOWN_DB = torch.load(args.database) AUTHORIZED_ID = None if args.display: cv2.namedWindow('frame', cv2.WINDOW_NORMAL) if args.fullscreen: cv2.namedWindow('frame', cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty('frame', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
# GYM: Environment lib import gym import gym_textgame from models import HistoryQLearner from replay_buffer import PrioritizedReplayBuffer from preprocess import sent2seq, initHist, addHistoryState from arguments import getArguments from utils import initDB, sendDocDB, sendModelDB if __name__ == "__main__": args = getArguments() es = initDB() # layer sizes epsilon = args.epsilon_start epsilon_step = (args.epsilon_start - args.epsilon_end) / args.epsilon_anneal_steps env = gym.make(args.env) env_eval = gym.make(args.env) num_actions = env.num_actions num_objects = env.num_objects vocab_size = env.vocab_space seq_len = env.seq_length hist_size = args.history_size model = HistoryQLearner(seq_len, vocab_size, args.embd_size, hist_size,
#!/usr/bin/env python3 import utils.gatepirate as gatepirate from utils import initDB initDB() var = gatepirate.ITKGatePirate(port='auto', pmode='serial') var.listen()