def main(argv): try: train_csv_path = None model_path = None batch_size = 128 epochs = 100 optlist, args = getopt.getopt(argv[1:], '', [ 'help', 'train=', 'model=', 'batch_size=', 'epochs=', ]) for opt, arg in optlist: if opt == '--help': utils.help() sys.exit(0) elif opt == '--train': train_csv_path = arg elif opt == '--model': model_path = arg elif opt == '--batch_size': batch_size = int(arg) elif opt == '--epochs': epochs = int(arg) if train_csv_path == None: print('The following values must be input') print('train') utils.help() sys.exit(1) train(train_csv_path, model_path, batch_size, epochs) except Exception as e: print(e) sys.exit(1)
def main(argv): try: predict_csv_path = None output_csv_path = None model_path = None batch_size = 128 input_length = 1600 window_size = 5 optlist, args = getopt.getopt(argv[1:], '', ['help', 'predict=', 'model=', 'batch_size=', 'output=', 'input_length=', 'window_size=']) for opt, arg in optlist: if opt == '--help': utils.help() sys.exit(0) elif opt == '--predict': predict_csv_path = arg elif opt == '--model': model_path = arg elif opt == '--batch_size': batch_size = int(arg) elif opt == '--output': output_csv_path = arg elif opt == '--input_length': input_length = int(arg) elif opt == '--window_size': window_size = int(arg) if predict_csv_path == None: print('The following values must be input') print('predict') utils.help() sys.exit(1) predict(predict_csv_path, output_csv_path, model_path, batch_size, input_length, window_size) except Exception as e: print(e) sys.exit(1)
def main(): argc = len(sys.argv) if argc == 2 and sys.argv[1] == '-h': print(utils.help()) sys.exit(0) elif argc == 5: try: n = int(sys.argv[1]) csvfile = sys.argv[2] px = float(sys.argv[3]) py = float(sys.argv[4]) if n <= 0: utils.error('Matrix must be > 0.') if 0 < px >= n: utils.error('Number must be inside the matrix.') if 0 < py >= n: utils.error('Number must be inside the matrix.') except ValueError: utils.error('Size must be integer and point must be floats.') else: utils.error('Missing command line argument.') #TODO: Check file matrix = func.fileToMatrix(n, csvfile) if matrix == None: utils.error('File error.') #End of error checking sol = func.solve(matrix, n, px, py) print("{:0.2f}".format(round(sol, 2)))
def get(self, got): if not got: self.response.out.write(utils.help(self.u, self.r, self.l)) return c = Sprunge.gql('WHERE name = :1', got).get() ua = self.request.headers['User-Agent'] term = True if ua.lower().find('curl')!=-1 or ua.lower().find('wget')!=-1 else False if not c: if not term: self.response.headers['Content-Type'] = 'text/plain; charset=UTF-8' self.response.out.write(got + ' not found') return syntax = self.request.query_string if not syntax: if not term: self.response.headers['Content-Type'] = 'text/plain; charset=UTF-8' self.response.out.write(c.content + '\n') return try: lexer = pygments.lexers.get_lexer_by_name(syntax) except: lexer = pygments.lexers.TextLexer() if not term: formatter = utils.MyHTMLFormatter(linenos='table', lineanchors='L', lineseparator='', anchorlinenos=True) self.response.out.write('''\ <!DOCTYPE html> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Code</title> <style type="text/css"> body { margin: 0; padding: 0 } .highlight { line-height: 125%; margin: 0; padding: 0; font-family: monospace } .highlight td { padding: 0; } .highlight td.code { width: 100%; } .highlight > .highlighttable { border-collapse: collapse; background: #f8f8f8; } .linenodiv { background-color: #f0f0f0; text-align: right; } .linenodiv > a { padding: 0 0.5em; text-align: right; display: block; } .line { height: 1.25em; white-space: nowrap; width:100%;display:-moz-inline-box;display:inline-block;} .linenodiv > a:link, .linenodiv > a:visited { color: gray; outline: none } .line:target { background-color: #ffffcc } .linehighlight { background-color: #ffffcc } ''') #.line:hover { background-color: #ffffcc } self.response.out.write(formatter.get_style_defs('.highlight')) self.response.out.write(''' </style> <div class="highlight"> ''') self.response.out.write(highlight(c.content, lexer, formatter)) self.response.out.write('''\ </div> ''') else: self.response.out.write(highlight(c.content, lexer, TerminalFormatter(bg='dark')))
def text_reply(message): if message.text == emoji.emojize(':warning: Сейчас'): bot.send_message(message.chat.id, schedule.get_now()) elif message.text == emoji.emojize(':eleven-thirty: Сегодня'): bot.send_message(message.chat.id, schedule.get_today()) elif message.text == emoji.emojize(':fast-forward_button: Завтра'): bot.send_message(message.chat.id, schedule.get_tomorrow()) elif message.text == emoji.emojize(':calendar: Неделя'): bot.send_message(message.chat.id, schedule.get_week()) elif message.text == emoji.emojize(':question_mark: Справка'): bot.send_message(message.chat.id, utils.help()) elif message.text == emoji.emojize(':warning: Сейчас'): bot.send_message(message.chat.id, schedule.get_now())
#!/usr/bin/python import sys, os, functools, utils def agg(a, b): # print(a, b) if not a: return b return a utils.help() res = functools.reduce(agg, utils.read_all(), []) utils.out("".join(res))
def help(debug=False): return utils.help(os.path.dirname(__file__), "SCR_TOF_help.txt", debug = debug)
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)
def help(message): if message.chat.id != config.group_id: config.the_bot.forward_message(config.group_id, message.chat.id, message.message_id) utils.help(message)
def main(): argc = len(sys.argv) if argc != 10: if argc >= 2 and sys.argv[1] == '-h': print(utils.help()) else: utils.error('Missing command line argument.') else: try: for i in range(1, 10): if float(sys.argv[i]) < 0: utils.error('Arguments must be >= 0.') except ValueError: utils.error('Arguments must be numbers.') #End of error checking n = [sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]] po = sys.argv[5] pw = sys.argv[6] pc = sys.argv[7] pb = sys.argv[8] ps = sys.argv[9] print("Resources: " + n[0] + " F1, " + n[1] + " F2, " + n[2] + " F3, " + n[3] + " F4\n") names = ["Oat", "Wheat", "Corn", "Barley", "Soy"] # 1 matrix = func.make_matrix(n[0], n[1], n[2], n[3], po, pw, pc, pb, ps) # while loop while func.loop_check_zero(matrix): # 2 pivot_col_num = func.find_max_neg_col(matrix) col = func.sel_col(matrix, pivot_col_num) # 3 pivot_row_num = func.sel_pivot_row_num(col, matrix) # 4 pivot_ele = matrix[pivot_row_num][pivot_col_num] func.pivot_one(pivot_row_num, matrix, pivot_col_num, pivot_ele) # 5 func.make_other_zero(matrix, pivot_row_num, pivot_col_num) quantities = [0, 0, 0, 0, 0] for i in range(5): col = func.sel_col(matrix, i) if col.count(1) == 1 and col.count(0) == len(matrix) - 1: quantities[i] = round(matrix[col.index(1)][len(matrix[0]) - 1], 3) if quantities[i] == 0: quantities[i] = int(quantities[i]) for i in range(len(names)): if quantities[i] == 0: print(names[i], ": 0 units at $", sys.argv[5 + i], "/unit", sep='') else: print(names[i], ": ", "{0:.2f}".format(quantities[i]), " units at $", sys.argv[5 + i], "/unit", sep='') total = 0 for i in range(5): total += quantities[i] * float(sys.argv[5 + i]) print("\nTotal production value:" + " ${0:.2f}".format(total))