def main(): init_database() analytics = initialize_analyticsreporting() data = get_events(analytics) if (data): save(data)
def main(): parser = argparse.ArgumentParser() parser.add_argument( "-f", "--full", action="store_true", help="crawl all pages instead of stopping at last seen", ) parser.add_argument( "-L", "--limit-pages", type=int, metavar="N", help="only crawl at most the first N pages of each club", ) parser.add_argument( "--legacy", action="store_true", help="also crawl VODs of now defunct SHY48 and CKG48", ) args = parser.parse_args() init_database(logger=logger) global seen_urls seen_urls = retrieve_seen_urls() club_ids = (1, 2, 3, 4, 5) if args.legacy else (1, 2, 3) for club_id in club_ids: crawl_club(club_id, limit_pages=args.limit_pages, full=args.full)
def create_app(): # Flask app = Flask(__name__) # config app.config.update(config.cf) # DB初期設定 init_database(app) return app
def _store_data(args): db_engine = database.create_engine(args.db_config) if args.which_table == 'create_empty': database.init_database(db_engine, resources.db_structure) else: table = database.Table.from_database(args.which_table, db_engine) row_generator = data_generators.RowGenerators.get( args.which_table, args, ) table.add_data(row_generator(args.language), row_generator.buffer_size)
def run(self): if self.init: database.init_database(self.sound_lib_dir, self.sound_lib_database, progress=self.update.emit, message=self.message_func) if self.message_func: self.message_func("Loading Database...") self.database = database.load_database(self.sound_lib_database, progress=self.update.emit) time.sleep(1) if self.close_prog_func: self.close_prog_func() if self.close_log_func: self.close_log_func()
def init_database(self): database.init_database() info = DealerInfo.find(exchange=self.exchange) if not info: info = DealerInfo.new(self.exchange) else: print "WARNING, dealer %s already in database" % self.exchange info.rooms = 0 self.info = info
def submission_thread(): """ This is the main submission thread, it listens to all new submissions in a subreddit, returns a post instance, extract image and text, fills out the database. If SIGINT or SIGTERM is received, the database connection will be closed and the program will be gracefully killed. """ logging.warning("Sleeping for 10 seconds. Waiting for the database to turn on...") time.sleep(10) killer = signal_handler.GracefulKiller conn = psycopg2.connect(dbname=config.db_name, user=config.db_user, password=config.db_pass, host=config.db_host, port=config.db_port) database.init_database(conn) for submission in subreddit.stream.submissions(): post = reddit.submission(submission) post_ID = str(post.id) logging.info("") logging.info("------------------------") logging.info(f"Starting new submission. {post_ID}") latest_posts = database.get_latest(conn) # If the post has been processed recently, # skip it then if (post_ID in latest_posts): logging.info("The post already has been evaluated.") continue formatted_text = validate_text(post) if (not formatted_text): database.add_record(conn, post_ID) continue citation = search_quote(conn, formatted_text, post) if (not citation): database.add_record(conn, post_ID) logging.info("Citation is not found.") continue database.add_record(conn, post_ID, citation) logging.info("Record has been added to the database.") show_out(conn) safe_kill(killer, conn)
def cmd_serve(): """Starts the HTTP web server on the configured socket.""" database.init_database() root = get_web_root() if root is None: logging.error("Could not find web root folder.") sys.exit(1) logging.info("Web root is %s" % root) os.chdir(root) serve_http(*settings.get("webapi_socket", "127.0.0.1:8080").split(":", 1))
def init_database(self): database.init_database() info = DealerInfo.find(exchange = self.exchange) if not info: info = DealerInfo.new(self.exchange) else: print "WARNING, dealer %s already in database" % self.exchange info.rooms = 0 self.info = info
def app(): """Create an app with testing environment.""" app = create_app('config.TestConfig') test_db = app.config.get('DATABASE').get('name') if os.path.exists(test_db): logger.info(' Deleting test database...') os.remove(test_db) logger.info(' Deleted test database!') with app.app_context(): init_database() create_task_table() init_seed() yield app
def create_app(): app = Flask(__name__) app.config.from_object("config") database.init_database(app) app.toolbar = DebugToolbarExtension(app) app.babel = Babel(app) @app.before_request def before_request(): g.context = {} # elixir.setup_all() return app
def cmd_run(*args): """ Run all server components. """ autocreate_configs() check_required_programs() #check_file_permissions() from database import init_database init_database() try: threads = get_threads() except Exception, e: print("Error: %s" % e, file=sys.stderr) print(traceback.format_exc(e), file=sys.stderr) sys.exit(1)
def main(): # set server's password args = get_args() password = args['password'] set_serverpass(password) # start database init_database() # register events for event in event_list: tunnel.on(event.name, event.func) for job in job_list: job.run() # start server tunnel.run()
def build(): init_database() con = connection() cur = con.cursor() cur.execute("DELETE FROM Posting") cur.execute("DELETE FROM IndexWord") con.commit() filenames = get_page_filenames() for filename in tqdm.tqdm(filenames): file = get_file(filename, "utf8") text = get_text(file) words = preprocess(text) for word in words: add_index(con, word[0], filename.replace("\\", "/").replace("../pages/", ""), word[1]) con.close()
def main(): parser = ArgumentParser(description='Runs the server for the groupmechatbot') parser.add_argument('-t', '--token', help='Groupme token', default='VArZCH69ta1GSoq1uK13k80Zhu0OJi5czkz93099') parser.add_argument('-a', '--account', help='Database account to access') parser.add_argument('-i', '--model-input-file', help='txt file for the model') parser.add_argument('-b', '--bot-id', help='bot id to use for groupme response', default='4a38538df10cf8273ed53752bc') parser.add_argument('-c', '--config-path', help='path to the db config file', required=True) args = parser.parse_args() LoggingEnv("GroupmeChatBot") request_params = {'token': args.token} post_params = {'bot_id': args.bot_id, 'text': 'Testing'} response_url = 'https://api.groupme.com/v3/groups/16915455/messages' request_helper = RequestHelper(response_url, request_params, post_params) database.init_database('groupmebot', args.account, args.config_path) chatbot = init_model(database, args.model_input_file) most_recent = MostRecentId(0, '') init_most_recent(most_recent) loop = asyncio.get_event_loop() try: asyncio.ensure_future(read_message(request_helper, most_recent, chatbot)) loop.run_forever() except KeyboardInterrupt: pass finally: logging.info('Closing loop') loop.close() request_helper.post_params['text'] = 'Crashing gracefully' requests.post('https://api.groupme.com/v3/bots/post', params=request_helper.post_params)
save_ip(result['ip'], result['status']) if result['status'] == STATUS_HAS_HTTP: http += 1 else: hiks += 1 # acknowledge total += 1 if total % 5 == 0: print("total saved: %d, http: %d, hikcams: %d" % (total, http, hiks)) ch.basic_ack(delivery_tag=method.delivery_tag) def recv_ips() -> None: """ starts receiving users from the queue """ chan.receive(RmqQueueName.FROM_WORKER, recv) # start consumer threading.Thread(target=chan.start).start() init_database() recv_ips()
def db() -> None: """Command line script for creating database tables.""" init_database()
Label(l, text="Prenom:").grid(row=3, column=0) prenom_label = Label(l, text="No Match!", fg="red") prenom_label.grid(row=3, column=1) Label(l, text="Ratio:").grid(row=4, column=0) ratio_label = Label(l, text="No Match!", fg="red") ratio_label.grid(row=4, column=1) n = TTK.Notebook(fenetre, width=width_W, height=(int(height_W / 2))) onglet1 = TTK.Frame(n) onglet2 = TTK.Frame(n) n.add(onglet1, text='Segmentation') n.add(onglet2, text='Polarisation') n.place(relx=0.50, rely=0.80, anchor=CENTER) label_center = Label(onglet1, image='') label_center.place(relx=0.20, rely=0.40, anchor=CENTER) label_border = Label(onglet1, image='') label_border.place(relx=0.50, rely=0.40, anchor=CENTER) label_final = Label(onglet1, image='') label_final.place(relx=0.80, rely=0.40, anchor=CENTER) label_polar = Label(onglet2, image='') label_polar.place(relx=0.50, rely=0.40, anchor=CENTER) database.init_database() fenetre.mainloop()
def start_conversation(): message = input("") states['current'] = check_state(message) connection = init_database() greeting(states) conversation()
self.v.value = 2 break limit_val = 10 except Exception as e: print(traceback.format_exc()) if '503' in str(e): print('503 from server') if '401' in str(e): print('401 from server') else: f = open('errs.txt', 'a') error = str(traceback.format_exc()) f.write(error) thread_count = 0 threads = [] for i in config.sub_settings: if i is not None: database.init_database(i[0], i[8]) threads.append(FindPosts(i)) if i[1] is not None or i[2] is not None or i[3] is not None: database.delete_old_loop(i) threads[thread_count].start() thread_count += 1 delete_comment() for i in range(0, len(threads)): threads[i].join()
def database(): from database import PerfVOD, db, init_database try: init_database() PerfVOD.create( canon_id="324479006241787906", l4c_club_id=1, l4c_id=2777, title="X队出道四周年", subtitle="TEAM X剧场公演", start_time=1555843500, sd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-liuchang/324479006241787906.m3u8", hd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-gaoqing/324479006241787906.m3u8", fhd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-gaoqing/324479006241787906.m3u8", ) PerfVOD.create( canon_id="326091353251188736", l4c_club_id=1, l4c_id=2774, title="莫寒咖啡店生日会", subtitle="参加成员:莫寒", start_time=1555836300, sd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-liuchang/326091353251188736.m3u8", hd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-gaoqing/326091353251188736.m3u8", fhd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-gaoqing/326091353251188736.m3u8", ) PerfVOD.create( canon_id="324479006245982208", l4c_club_id=1, l4c_id=2772, title="《重生计划》剧场公演", subtitle="莫寒生日公演", start_time=1555825500, sd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-liuchang/324479006245982208.m3u8", hd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-gaoqing/324479006245982208.m3u8", fhd_stream= "http://cychengyuan-vod.48.cn/snh/20190421/9999-gaoqing/324479006245982208.m3u8", ) PerfVOD.create( canon_id="324918581187645440", l4c_club_id=2, l4c_id=2775, title="《UNIVERSE》剧场公演", subtitle="TeamE剧场公演", start_time=1555845900, sd_stream= "http://cychengyuan-vod.48.cn/bej/20190421/9999-liuchang/324918581187645440.m3u8", hd_stream= "http://cychengyuan-vod.48.cn/bej/20190421/9999-gaoqing/324918581187645440.m3u8", fhd_stream= "http://cychengyuan-vod.48.cn/bej/20190421/9999-gaoqing/324918581187645440.m3u8", ) PerfVOD.create( canon_id="324479006241787904", l4c_club_id=3, l4c_id=2773, title="《Fiona.N》剧场公演", subtitle="孙馨生日公演", start_time=1555826400, sd_stream= "http://cychengyuan-vod.48.cn/gnz/20190421/9999-liuchang/324479006241787904.m3u8", hd_stream= "http://cychengyuan-vod.48.cn/gnz/20190421/9999-gaoqing/324479006241787904.m3u8", fhd_stream= "http://cychengyuan-vod.48.cn/gnz/20190421/9999-gaoqing/324479006241787904.m3u8", ) yield finally: PerfVOD.delete().execute()
from database import init_database from datetime import timedelta from flask import Flask, g, render_template, session from flask.ext.login import LoginManager, current_user from time import time from website import jinja_filters from website.configuration import Config final_parsec_website = Flask('website') final_parsec_website.config.from_object(Config) final_parsec_website.debug = final_parsec_website.config['APP_DEBUG'] final_parsec_website.jinja_env.filters['pretty_date'] = jinja_filters.pretty_date init_database(final_parsec_website, g) @final_parsec_website.errorhandler(500) def page_error(error): """ User is displayed this page if an error occurs when attempting to render page. """ return render_template('error_pages/500.html', error=error), 500 @final_parsec_website.errorhandler(404) def page_missing(error): """ User is displayed this page if they attempt to go to a URL that doesn't exist. """
'''db5 - Focusing on the analytics''' # third-party libraries import pandas as pd import database SQL_AGE = ''' SELECT AGE as age, COUNT(*) as count FROM clean GROUP BY AGE''' SQL_ALL = 'SELECT * FROM clean' db = database.init_database() # SQL query turned into a dataframe age_table = pd.read_sql_query(SQL_AGE, db) print(age_table) # SQL query loading all data into dataframe df = pd.read_sql_query(SQL_ALL, db, index_col='MATCHKEY') print(df.describe())
import sqlite3 from database import init_database init_database('master.db') db = sqlite3.connect('master.db') db.execute('''INSERT INTO tractor (codTractor,latitud,longitud,altura,humedad,peso,temperatura,composicion,actual) VALUES ('A001','-23.6075322','-58.0485704','22','30',200,30,'descripcion de la composicion del terreno',1)''') db.execute('''INSERT INTO tractor (codTractor,latitud,longitud,altura,humedad,peso,temperatura,composicion,actual) VALUES ('B003','-22.80','-58.5','22','30',200,30,'descripcion de la composicion del terreno',1)''') db.execute('''INSERT INTO tractor (codTractor,latitud,longitud,altura,humedad,peso,temperatura,composicion,actual) VALUES ('C005','-26.5','-55.5','22','30',200,30,'descripcion de la composicion del terreno',1)''') db.close()
''' Created on Aug 12, 2012 @author: adetolaadewodu ''' from database import init_database from sqlalchemy import create_engine, MetaData from sqlalchemy import Table init_database() engine = create_engine( "mysql+pymysql://root:@localhost/pydb") metadata = MetaData(bind=engine) # Create database user = Table('user', metadata, autoload=True)
import flask_security import wtforms import flask_assets import datetime from flask_security.utils import login_user import flask_debugtoolbar import flask import flask_migrate import forms import admin import celery as celery_lib app = Flask(__name__) read_config(app) init_database(app) def make_celery(app, celery): celery.main = app.import_name celery.conf.result_backend = app.config['CELERY_RESULT_BACKEND'] celery.conf.broker_url = app.config['CELERY_BROKER_URL'] celery.conf.beat_schedule = app.config['CELERY_SCHEDULE'] celery.conf.timezone = 'UTC' class ContextTask(celery.Task): def __call__(self, *args, **kwargs): with app.app_context(): return self.run(*args, **kwargs) celery.Task = ContextTask
print("Starting searching...") counter = 0 sub = 0 for submission in subreddit.top('all', limit=10000): sub += 1 print("{} --> Starting new submission {}".format(sub, submission.id)) submission.comments.replace_more(limit=1000) for comment in submission.comments: counter += 1 print("{}. Doing {}".format(counter, comment.id)) author = comment.author if (not database.is_logged(conn, author)): database.add_user(conn, author, comment.id) print("Added {}".format(author)) def ban_users(): all_users = database.get_all() banned = [x for x in all_users if random.randint(1, 100) % 2 == 0] # list banned will contain everyone that needs to get banned not_banned = [x for x in all_users if not x in banned] for user in banned: subreddit.flair.set(user,'perished') #Subreddit.banned.add(user, ban_reason='The universe needs balance') for user in not_banned: subreddit.flair.set(user,'survived') database.init_database(conn) find_users() conn.close()
def before_request(): # 在执行用户请求之前 init_database() uploads_directory() app.config['users'] = getAllUser() app.config['Title'] = u"{str} 的记事本".format( str=u" 和 ".join(app.config['users']))
from flask import (Flask, request) from flask_restful import Api, reqparse, Resource from flask_cors import CORS from database import init_database from routing import Routing from configurations import configurations from models.user import User app = Flask(__name__) app.secret_key = configurations['secret_key'] CORS(app, supports_credentials=True) db = init_database(app) api = Api(app) Routing.add_resources(api) if __name__ == '__main__': with app.app_context(): db.create_all() app.run(debug=True)
def init_packages(): with open("packages") as f: for v in f.readlines(): pkgname, pkgver = v.strip().split() PACKAGES[pkgname] = pkgver print("Parsed packages") # # key: pkgname-pkgver # # Metadata # AVGS = {} # for avg in AVGS.values(): # fmt_avg(avg[0]) SESSION = init_database() def refresh(): j = get_recent_nvd_data() commit_cve(SESSION, j) print("[*] Updated Recent from NVD") j = get_all_nvd_data() commit_cve(SESSION, j) print("[*] Updated 2020.json from NVD") def find_all(check_tracker=False): pass
from datetime import timedelta from flask import Flask, g, render_template, session from flask.ext.login import LoginManager, current_user from time import time from website import jinja_filters from website.configuration import Config final_parsec_website = Flask('website') final_parsec_website.config.from_object(Config) final_parsec_website.debug = final_parsec_website.config['APP_DEBUG'] final_parsec_website.jinja_env.filters[ 'pretty_date'] = jinja_filters.pretty_date init_database(final_parsec_website, g) @final_parsec_website.errorhandler(500) def page_error(error): """ User is displayed this page if an error occurs when attempting to render page. """ return render_template('error_pages/500.html', error=error), 500 @final_parsec_website.errorhandler(404) def page_missing(error): """ User is displayed this page if they attempt to go to a URL that doesn't exist. """
import bottle import gallery import images import FBlogin import database as db db.init_database() app = application = bottle.default_app() if __name__ == '__main__': bottle.run(host = '127.0.0.1', port = 8080)