def run(self, options): """ Beginning monitor thread. Sleep and wait for interrupt. """ # Start plugin manager plugin_manager.load_all_plugins() # Start monitor thread paths = settings.get('core', 'base').split(',') content.set_push_func(plugin_manager.push_queue) if options.rebuild: content.rebuild() self.monitor = Monitor(paths) #self.monitor.set_push_queue_func(plugin_manager.push_queue) self.monitor.start() # Register bonjour if settings.get('core', 'aggregation') == 'True': self.bonjour = Bonjour() self.bonjour.register(socket.gethostname(), '_mediaplat._tcp', 9020) self.server.serve_forever()
def _prepare_browse(self, request): self.args['start'] = str(request.GET.get('start', 0)) self.args['count'] = str(request.GET.get('count', settings.get('web', 'count_per_page'))) page = int(request.GET.get('page', '0')) if self.args['id'].find('image') < 0: request_count = int(settings.get('web', 'count_per_page')) else: request_count = int(settings.get('web', 'image_per_page')) start_index = request_count * page self.args['self'] = content.browse_metadata(self.args['id']) if self.args['self'].get('type') == 'container': self.args['single'] = False self.args['parents'] = content.parents(self.args['id']) self.args['rows'] = content.browse_children(self.args['id'], start_index = start_index, request_count = request_count) self.args['cur_page'] = page page_node = self.args['self'] else: self.args['single'] = True self.args['parents'] = content.parents(self.args['self'].get('pid')) self.args['rows'] = [ self.args['self'] ] self.args['cur_page'] = page #page_node = content.browse_metadata(self.args['self'].get('pid')) page_node = self.args['self'] self.args['page_range'] = range(page_node.get('child_count', 0) / request_count + 1) items = page_node.get('child_item_count', 0) containers = page_node.get('child_container_count', 0) self.args['items'] = pretty_count([(containers, " container", " containers"), (items, " item", " items")])
def GET(self): databases = get_blast_databases(settings.get('BLAST_EXECUTABLE_PATH'), settings.get('BLAST_DATABASE_PATH')) programs = {'nucleotide': NBLAST, 'protein': PBLAST} qs = web.input() identifier = qs.get('settings') db = qs.get('db', '') pgrm = qs.get('pgrm', '') seq = qs.get('seq', '') adv = '' if identifier is not None: with open('{0}{1}.json'.format(settings.get('BLAST_RESULTS_PATH'), identifier)) as sp: opt = json.loads(sp.read()) db = opt['database'] pgrm = opt['program'] seq = opt['sequence'] adv = opt['advanced'] return render_template('index.html', base_template = settings.get('BASE_TEMPLATE'), settings = settings, title="pyBlast | Enter sequence to BLAST", databases = databases, programs = programs, uuid = uuid.uuid4(), db = db, pgrm = pgrm, sequence = seq, advanced = adv, rndm = random.random(), )
def plugin_main(self, new_file): inode, file_path = new_file ext = path.splitext(file_path)[1][1:].lower() thumb_dir = settings.get('thumbnail', 'path') thumb_file = path.join(thumb_dir, inode + '.jpg') # Extract base image if ext in self.EXT_VIDEO: fnull = open(devnull, 'w') command = [ 'ffmpeg', '-i', file_path, '-y', '-vframes', '1', '-ss', '00:00:01', '-an', thumb_file ] call(command, shell=False, stdout=fnull, stderr=fnull) fnull.close() elif ext in self.EXT_AUDIO: media_info = MediaInfo.parse(file_path) if media_info.tracks[0].cover == 'Yes': cover_data = media_info.tracks[0].cover_data open(thumb_file, 'wb').write(a2b_base64(cover_data)) else: audio_dir = path.dirname(file_path) for folder_cover in [ 'Folder.jpg', 'folder.jpg', 'Cover.jpg', 'cover.jpg' ]: audio_cover = path.join(audio_dir, folder_cover) if path.exists(audio_cover): command = ['convert', audio_cover, thumb_file] call(command) else: if not ext in self.EXT_EPEG_SUPPORT: if ext == 'gif': command = ['convert', file_path + "[0]", thumb_file] else: command = ['convert', file_path, thumb_file] call(command) else: thumb_file = file_path # Generate thumbnail for size in settings.get('thumbnail', 'size').split(','): WxH = settings.get('thumbnail', size) filename = [inode, size, 'jpg'] command = [ 'epeg', '-m', WxH, thumb_file, path.join(thumb_dir, '.'.join(filename)) ] call(command) self.push_back({ 'uid': inode, 'module': self.name, 'has_thumbnail': 'true' }) log.debug("{} module finished: {}".format(self.name, new_file[1]))
def check_schedule(): try: if int(settings.get("update_schedule")) > 0: print("[*] Sleeping until next run to confirm hostnames") while True: # Converting days to seconds and sleeping until next run time.sleep(int(settings.get("update_schedule")) * 86400) main() except ValueError: pass
def GET(self, db, sequence): seqs = sequence.split(',') results = [] for s in seqs: results.append([s, get_sequence_from_database(settings.get('BLAST_EXECUTABLE_PATH'), settings.get('BLAST_DATABASE_PATH')+db, s)]) return render_template('sequences.html', base_template = settings.get('BASE_TEMPLATE'), settings = settings, title = 'pyBlast | Retrieved sequences', results = results, )
def observe(): try: with rabbitpy.Connection('amqp://{username}:{password}@{host}:{port}/{vhost}'.format( username=settings.get('RABBITMQ_USERNAME'), password=settings.get('RABBITMQ_PASSWORD'), host=settings.get('RABBITMQ_HOST'), port=settings.get('RABBITMQ_PORT'), vhost=settings.get('RABBITMQ_VHOST') )) as conn: with conn.channel() as channel: channel.enable_publisher_confirms() Ayumi.set_rabbitpy_channel(channel) Ayumi.info("Now connected AMQP provider.", color=Ayumi.GREEN) event_handler = IzumiHandler(channel) observer = Observer() observer.schedule(event_handler, settings.get('KOTEN_WATCH_PATH', DEFAULT_WATCH_PATH), recursive=True) observer.start() Ayumi.info("Now observing: {}".format(settings.get('KOTEN_WATCH_PATH', DEFAULT_WATCH_PATH)), color=Ayumi.BLUE) try: while True: time.sleep(settings.get('KOTEN_SLEEP_INTERVAL', DEFAULT_SLEEP_INTERVAL)) except: Ayumi.warning("Detected SIGKILL or error, returning...", color=Ayumi.YELLOW) observer.stop() observer.join() except rabbitpy.exceptions.AMQPConnectionForced: Ayumi.rabbitpy_channel = None Ayumi.critical("Operator manually closed RabbitMQ connection, shutting down.", color=Ayumi.RED) # Use return for now because in some cases, calling exit() may invoke the retry() header. return
def setUp(self): super(TestVerifyBase, self).setUp() # specialize the test event for the verification calls self.test_event['method'] = "GET" self.test_event['query']['hub.verify_token'] = settings.get("verifyToken") self.test_event['query']['hub.challenge'] = "abcdefgh"
def on_delete(self, w, event): x, y = self.get_size() settings["window_width"] = x settings["window_height"] = y if settings.get("tray_icon", False): self.set_visibility(False) return True
def _load_accepted_shows() -> Dict[str, str]: accepted_shows = settings.get('ACQUISITION_RSS_ACCEPTED_SHOWS', list()) show_name_map = dict() for show in accepted_shows: stripped_title, override_title = _parse_accepted_shows(show) show_name_map[stripped_title] = override_title return show_name_map
def verify_webhook(query): """ Handles the API verification step from Facebook, which consists of a GET to the webhook with the following querystring args: hub.verify_token = the verification token you supplied when setting up the web hook. hub.challenge = the challenge value Facebook expects back. The expected value for the verify_token is stored in config/settings.json, which is read in webhook.pay and passed in the settings param to this call. """ my_verify_token = settings.get("verifyToken") verify_token = query.get("hub.verify_token") if not verify_token: raise Exception("400 Bad Request; missing verification token") if verify_token == my_verify_token: challenge = query.get("hub.challenge") if not challenge: raise Exception("400 Bad Request; missing challenge") else: return challenge else: raise Exception("403 Forbidden; verification token mismatch")
def __init__(self, main_window): self.tray = None self.main_window = main_window if settings.get("tray_icon", False): self._create_tray_icon(self.main_window) settings.connect("tray_icon", self._on_tray_conf_changed)
def getGeneralSetting(self, setting, default=''): value = settings.get('General', setting) #value = settings['plugin-%s/%s' % (self.name, setting)] if value == '': value = default return value
def pygame_init(): '''Initialise pygame''' pygame.init() pygame.font.init() if settings.getboolean('Sound', 'enabled'): pygame.mixer.init() pygame.display.set_caption(settings.get('Project','name'))
def _do_audio(self, request): if request.method == 'POST': try: action = request.POST.get('action') if action == 'Start Play': uid = request.POST.get('uid') device_idx = request.POST.get('device_idx') host = request.META.get('HTTP_HOST') airplay.send_audio(host, uid, int(device_idx)) elif action == 'Refresh Device' and \ settings.get('airplay', 'enable') == 'True': airplay.discovery() except: log.exception('Fail to airplay send_audio') self.args['id'] = str(request.GET.get('id', content.AUDIO)) self._prepare_browse(request) uid = self.args['id'] if uid == 'audio_album' or uid == 'audio_artist': self.args['view_mode'] = 'on' for row in self.args['rows']: if uid == 'audio_album': row['audiotitle'] = row.get('album', '') row['audiodesc'] = row.get('artist', '') elif uid == 'audio_artist': row['audiotitle'] = row.get('artist', '') row['audiodesc'] = pretty_count([(row.get('child_count', '0'), " Song", " Songs")]) else: for row in self.args['rows']: self._pretty_format(request, row) self.args['cur_menu'] = 'audio' return ('audio.html', self.args)
def waifu(ctx, gender=None, search_for=None, is_otp=False): if ctx.command == "waifu" or gender == "waifu": list_name = "Waifu" end_tag = ["1girl", "solo"] else: list_name = "Husbando" end_tag = ["-1girl", "-female", "1boy", "solo"] result = () path = os.path.join(ctx.bot.config_path, '{} List.yaml'.format(list_name)) char_list = yaml_to_list(path, list_name.lower()) # This is used so they can't get aroun dbeing limited with x cmd # Plus to the odd series to make people actually use other cmds 😠. ignore = ["high-school-dxd", "love-live", "aoki-hagane-no-arpeggio", "kantai-collection", "aikatsu", "akb0048", "idolmaster", "idolmaster-cinderella-girls"] matched = [] if search_for is None: search_for = ctx.args if len(search_for) >= 5 and slugify(search_for) not in ignore: result = filter_per_series(char_list, search_for, 4) if not result: result = random.choice(char_list) name = re.sub("[\(\[].*?[\)\]]", "", result[0]).strip() # Remove () and [] series = result[1].get('series', None) otp_image = result[1].get('otp image', None) if is_otp: return name, series, otp_image start_path = settings.get('image_location', os.path.join(os.path.realpath(__file__), 'images')) path_name = os.path.join(start_path, list_name, slugify(result[0])) end_tag.append(name.replace(" ", "_")) reply_text = "Your {} is {} ({})".format(list_name, name, series) media_args = {'tags': end_tag} reply_media = get_media(path=path_name, ctx=ctx, media_args=media_args) return reply_text, reply_media
def _do_image(self, request): if request.method == 'POST': try: action = request.POST.get('action') if action == 'Start Play': uid = request.POST.get('uid') device_idx = request.POST.get('device_idx') airplay.send_image(uid, int(device_idx)) elif action == 'Refresh Device' and \ settings.get('airplay', 'enable') == 'True': airplay.discovery() except: log.exception('Fail to airplay send_image') self.args['id'] = str(request.GET.get('id', content.IMAGE)) self.args['devices'] = airplay.devices self._prepare_browse(request) if self.args['self'].get('child_container_count', 0) != 0: for row in self.args['rows']: self._pretty_format(request, row) else: self.args['view_mode'] = 'on' content.sort(self.args['rows'], 'ratio') for row in self.args['rows']: row['thumbnail_width'], row['thumbnail_height'] = \ get_resize(row.get('width', 0), row.get('height', 0), 180, 135) self.args['cur_menu'] = 'image' return ('image.html', self.args)
def _on_tray_conf_changed(self, *args): if not settings.get("tray_icon", False): self.tray.set_visible(False) else: if not self.tray: self._create_tray_icon(self.main_window) else: self.tray.set_visible(True)
def plugin_main(self, new_file): inode, file_path = new_file ext = path.splitext(file_path)[1][1:].lower() thumb_dir = settings.get('thumbnail', 'path') thumb_file = path.join(thumb_dir, inode + '.jpg') # Extract base image if ext in self.EXT_VIDEO: fnull = open(devnull, 'w') command = ['ffmpeg', '-i', file_path, '-y', '-vframes', '1', '-ss', '00:00:01', '-an', thumb_file] call(command, shell = False, stdout = fnull, stderr = fnull) fnull.close() elif ext in self.EXT_AUDIO: media_info = MediaInfo.parse(file_path) if media_info.tracks[0].cover == 'Yes': cover_data = media_info.tracks[0].cover_data open(thumb_file,'wb').write(a2b_base64(cover_data)) else: audio_dir = path.dirname(file_path) for folder_cover in ['Folder.jpg', 'folder.jpg', 'Cover.jpg', 'cover.jpg']: audio_cover = path.join(audio_dir, folder_cover) if path.exists(audio_cover): command = ['convert', audio_cover, thumb_file] call(command) else: if not ext in self.EXT_EPEG_SUPPORT: if ext == 'gif': command = ['convert', file_path + "[0]", thumb_file] else: command = ['convert', file_path, thumb_file] call(command) else: thumb_file = file_path # Generate thumbnail for size in settings.get('thumbnail', 'size').split(','): WxH = settings.get('thumbnail', size) filename = [ inode, size, 'jpg' ] command = ['epeg', '-m', WxH, thumb_file, path.join(thumb_dir, '.'.join(filename))] call(command) self.push_back({'uid' : inode, 'module' : self.name, 'has_thumbnail': 'true'}) log.debug("{} module finished: {}".format(self.name, new_file[1]))
def __init__(self): self._set_config() self.db = Connection( config.DB_HOST, config.DB_NAME, config.DB_USER, config.DB_PSWD, settings.get('debug')) #重写参数 ehandlers = [ x + (dict(database = self.db),) for x in handlers] Application.__init__(self,handlers = ehandlers,default_host='localhsot',transforms=None,**settings)
def send_notification(self, from_email="", to_email="", from_number="", to_number="", msg_head="", msg_body=""): print("[*] Sending update notification") # Validating if the user has chosen email option and sending email using EmailMessage() and smtplib if settings.get("send_email"): msg = EmailMessage() msg["Subject"] = msg_head msg["From"] = from_email msg["To"] = to_email msg.set_content(msg_body) try: with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp: try: smtp.login(self.gmail_username, self.gmail_password) smtp.send_message(msg) except smtplib.SMTPAuthenticationError: print( "[X] Error sending email - check receiver email or sender email and password\n\t \ [!] Make sure less secure apps is enabled on the sender email\n\t \ [!] Make sure you haven't been blocked") except socket.gaierror: print( "[X] Error sending email - check your internet connection") # Validating if the user has chosen sms option and sending sms using twilio API if settings.get("send_sms"): twilio_client = Client(self.twilio_account_sid, self.twilio_auth_token) twilio_client.messages \ .create( body = msg_body, from_= from_number, to = to_number )
def _display_single(self, uid, device_idx): full_path = content.fullpath(uid) unit_time = settings.get('airplay', 'time_per_slide') if full_path is not None: data = open(full_path).read() self.header['Content-Length'] = len(data) request = urllib2.Request('http://{}:7000/photo'.format(self.devices[device_idx]), data=data, headers=self.header) request.get_method = lambda: 'PUT' url = self.opener.open(request) time.sleep(int(unit_time))
def get_file(file_name): url = file_name if settings.get('url_prefix'): url = "%s/%s" % (settings['url_prefix'], file_name) content = None try: resp = requests.get(url) content = resp.content except: raise return content
def register_manager(mydb, args): email = args.get('email') username = args.get('username') password = args.get('password') mycollection = mydb[user_db()] # check to see if user is already in database results = mycollection.find({'username': username}) results_email = mycollection.find({'email': email}) if len(list(results)) > 0 or len(list(results_email)) > 0: return render_template('register.html', error='Username or email already in use') # get hash salt for hashing password hash_salt = get_salt(12) # encrypt passowrd pass_hash = pwd_context.hash(password + hash_salt) # create user object to store in database user_info = { '_id': get_next_Value(mycollection, 'id_values', 1), 'username': username, 'email': email, 'password': pass_hash, 'salt': hash_salt, 'activated': 'False', 'uploads': [], 'requests_to': [], 'requests_from': [] } random_string = get_salt(45) # send confirmation email to verify valid email link_with_url = request.url_root + 'confirm_email?email={}&pw={}'.format( email, random_string) message = CONFIRM_EMAIL.format(link_with_url) email_sent = send_email(email, 'Confirm Email', message) if not email_sent: return render_template('register.html', error='Could not verify email.') confirm_email_obj = { 'username': username, '_id': user_info.get('_id'), 'email': email, 'pw': random_string, 'data': get_date_time() } email_collections = mydb[settings.get('VERIFY_EMAIL_DB')] email_collections.insert_one(confirm_email_obj) mycollection.insert_one(user_info) return render_template('confirm_email.html')
def main(): # 接卸命令行 参数 tornado.options.parse_command_line() if settings.get('debug') != True: options.log_file_prefix = config.log_file_prefix options.logging = config.log_level """服务器启动文件""" app = Application(urls, **settings) http_server = HTTPServer(app) http_server.listen(options['port']) IOLoop.current().start()
def thumbnail_serve(request, uid, size): uid = content.original_uid(uid) if uid[0] == 'v': uid = uid[1:] thumb_dir = settings.get('thumbnail', 'path') full_path = path.join(thumb_dir, '{}.{}.jpg'.format(uid, size)) if full_path is None: log.error('requested uid({}) or size({})is invalid'.format(uid, size)) raise Http404 return static.serve(request, path=full_path, document_root='/')
def POST(self, identifier): options = web.input() return render_template('results_container.html', base_template = settings.get('BASE_TEMPLATE'), settings = settings, title="pyBlast | BLAST results", identifier = identifier, options = json.dumps(options), execute = True, rndm = random.random(), )
def get_module_log_level(name): """Reads config file for a log level set for this module.""" try: log_level = settings.get('logs').get('level') if log_level.upper() in LEVELS: return log_level except AttributeError: # if the logs section doesn't exist, use default return LEVEL if log_level == "": return LEVEL
def populate_resources(): resourceJSON = settings.get('plugin-GoogleCalendar', 'Resources') resources = json.loads(resourceJSON) # print(resources) for res in resources: # print(res) if not Resource.query.filter_by(name=res['resourceName']).first(): print(f"Adding new resource: {res['resourceName']}") new_resource = Resource(name=res['resourceName'], email=res['resourceEmail']) db.session.add(new_resource) db.session.commit()
def POST(self, identifier): options = web.input() web.header('Content-type', 'application/json') try: database = get_blast_database_from_title(settings.get('BLAST_EXECUTABLE_PATH'),settings.get('BLAST_DATABASE_PATH'),options.database) #database = settings.get('BLAST_DATABASE_PATH')+options.database program = settings.get('BLAST_EXECUTABLE_PATH')+options.program sequence = options.sequence advanced = options.advanced out, err = run_blast(database, program, settings.get('BLAST_RESULTS_PATH'), identifier, sequence, advanced) with open('{0}/{1}.json'.format(settings.get('BLAST_RESULTS_PATH'), identifier), 'w+') as sp: sp.write(json.dumps({ 'database': options.database, 'program': options.program, 'sequence': sequence, 'advanced': advanced, })) return json.dumps({'running': True, 'out': out, 'err': err}) except KeyError: web.ctx.status = 400 return json.dumps({'running': False})
def GET(self, identifier): file_loc = "{0}{1}.xml".format(settings.get('BLAST_RESULTS_PATH'), identifier) qs = web.input() cutoff = qs.get('cutoff') processed = None exists = False with open(file_loc) as results: if cutoff is not None: processed = process_blast_result(results.read(), cutoff=float(cutoff)) else: processed = process_blast_result(results.read()) exists = True return render_template('results_container.html', base_template = settings.get('BASE_TEMPLATE'), settings = settings, title="pyBlast | BLAST results", identifier = identifier, rndm = random.random(), uuid = uuid.uuid4(), results = processed, exists = exists, )
def on_new_file(src_path, channel): show_name = None episode_name = None new_file = src_path.replace(os.path.commonpath([settings.get('KOTEN_WATCH_PATH', DEFAULT_WATCH_PATH), src_path]) + "/", "") if m := util._show_manually_specified(new_file): Ayumi.info("Detected show name and episode name in event, using Mode 1.") show_name = m.group(1) episode_name = util._clean_episode_name(m.group(2)) Ayumi.info("New show name: {}".format(show_name), color=Ayumi.LYELLOW) Ayumi.info("New episode name: {}".format(episode_name), color=Ayumi.LYELLOW)
def send_email(recipient, subject, msg): try: #server = SMTP('smtp.gmail.com', 587) server = SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(settings.get('EMAIL_ADDRESS'), settings.get('EMAIL_PASSWORD')) message = 'Subject: {}\n\n{}'.format(subject, msg) # print(message) server.sendmail(settings.get('EMAIL_ADDRESS'), recipient, message) server.quit() # print('Success: Email sent!') return True # print(settings.get('PASSWORD')) # print(settings.get('EMAIL_ADDRESS')) except Exception as error: print('error sending message', error) return False
class GithubClient: API_BASE_URL = settings.get('API_BASE_URL', default=None) @classmethod def get_repos_by_user(cls, user): url = f'{cls.API_BASE_URL}/users/{user}/repos' response = requests.get(url) if response.status_code == 200: # todo: verificar todos os dados que tenho de retorno return {'status_code': 200, 'body': response.json()} else: return {'status_code': response.status_code, 'body': f'Error: Erro na requisição {url}'}
def setUp(self): logger.info("\n\n>>>>TEST CASE: {}".format(self.id())) # set up the test event, derived classes will fill out the # rest for their specific test cases self.test_event = json.loads(""" { "accessToken": "", "method": "", "body": {}, "headers": {}, "params": {}, "query": { "access_token": "" } } """ ) # needed for all test cases self.test_event['accessToken'] = settings.get("accessToken") self.test_event['query']['access_token'] = settings.get("accessToken")
def __init__(self, screen, screen_stack, next_screen): ContinueScreen.__init__(self, screen, screen_stack, next_screen) font = pygame.font.SysFont("Vera", 80) small_font = pygame.font.SysFont("Vera", 50) self.title = font.render(settings.get("Project", "name"), True, (255, 255, 0)) self.subtitle = small_font.render("Click to start...", True, (255, 255, 255)) self.blink_time = 200 # time subtitle is hidden per blink cycle in ms self.blink_period = 1000 # time for one blink cycle in ms self.blink_offset = self.blink_time # current time offset in blink cycle if settings.getboolean("Sound", "enabled"): self.music = resource.file_path("beep.ogg") else: self.music = None self.loop_music = 1
def _load_shows_map() -> Dict[str, str]: shows_map = settings.get( 'ACQUISITION_DOWNLOAD_BITTORRENT_SHOWS_MAP', []) Ayumi.debug("Fetched shows map from config: {}".format(shows_map)) show_name_map = dict() Ayumi.debug("Creating a stripped title to override title mapping...") for show in shows_map: stripped_title, override_title = _parse_shows_map(show) show_name_map[stripped_title] = override_title Ayumi.debug("Mapped {} to key {}.".format( override_title, stripped_title)) return show_name_map
def _display_single(self, uid, device_idx): full_path = content.fullpath(uid) unit_time = settings.get('airplay', 'time_per_slide') if full_path is not None: data = open(full_path).read() self.header['Content-Length'] = len(data) request = urllib2.Request('http://{}:7000/photo'.format( self.devices[device_idx]), data=data, headers=self.header) request.get_method = lambda: 'PUT' url = self.opener.open(request) time.sleep(int(unit_time))
def _do_video(self, request): self.args['id'] = str(request.GET.get('id', content.VIDEO)) self._prepare_browse(request) if self.args['self'].get('child_container_count', 0) != 0: for row in self.args['rows']: self._pretty_format(request, row) else: self.args['view_mode'] = 'on' for row in self.args['rows']: row['video_width'], row['video_height'] = \ get_resize(row.get('width', 0), row.get('height', 0), 900, 600) row['fullpath'] = content.fullpath(row['uid']).lstrip(settings.get("web", "path_base")) self.args['cur_menu'] = 'video' return ('video.html', self.args)
def rebuild(self): log.info("Rebuild database and thumbnails") cursor = self.conn.cursor() for table in self.TABLES.iterkeys(): query = "DELETE FROM {}".format(table) cursor.execute(query) self.conn.commit() cursor.close() thumb_dir = settings.get("thumbnail", "path") for base, dirs, files, in os.walk(thumb_dir): for file in files: os.remove(os.path.join(base, file)) self.buildup_tree()
def fate_servant_cmd(ctx): # NOTE: Still not finished on the list side. start_path = settings.get('image_location', os.path.join(os.path.realpath(__file__), 'images')) team = [] for x in range(0, 3): picked = False while True: rand = random.randint(0, 100) if rand <= 50: picked = random.choice(["Saber", "Archer", "Lancer"]) elif 51 <= rand <= 70: picked = random.choice(["Rider", "Caster", "Assassin"]) elif 71 <= rand <= 90: picked = random.choice(["Berserker", "Alter Ego", "Shielder"]) elif 91 <= rand <= 100: picked = random.choice(["Ruler", "Avenger", "Moon Cancer"]) if picked in team: continue team.append(picked) break final_entries = [] final_images = [] had_false = False for member in team: list_name = "Waifu" # temp no male if member in ["Saber", "Archer", "Lancer", "Rider", "Caster", "Assassin"] and random.randint(0, 100) > 195: list_name = "Husbando" path = os.path.join(ctx.bot.config_path, '{} List.yaml'.format(list_name)) char_list = yaml_to_list(path, "fate/servant/{}".format(member.lower().replace(" ", "_"))) char = random.choice(char_list) path_name = os.path.join(start_path, list_name, slugify(char[0])) image = get_media(path=path_name, media_args={}) if not image: had_false = True final_entries.append(char) final_images.append(image) reply_media = False if not had_false: reply_media = create_otp_image(otp_results=final_images, width_size=0, height_size=1000, is_otp=False) reply_text = "Your Fate/Grand Order Team is:\n{} ({})\n{} ({})\n{} ({})".format( re.sub("[\(\[].*?[\)\]]", "", final_entries[0][0]).strip(), team[0], re.sub("[\(\[].*?[\)\]]", "", final_entries[1][0]).strip(), team[1], re.sub("[\(\[].*?[\)\]]", "", final_entries[2][0]).strip(), team[2]) return reply_text, reply_media
def send(self, data, timestamp=None): payload = { "sampling_rate": self.sampling_rate, "sensordatavalues": [] } if timestamp: payload['timestamp'] = timestamp for key, value in data.iteritems(): d = {'value': value, 'value_type': key} payload['sensordatavalues'].append(d) headers = {'SENSOR': settings.get(self.sensor_uid), 'Content-Type': 'application/json'} r = requests.post(self.url, data=json.dumps(payload), headers=headers, verify=False) print(r.status_code) print(r.text)
def connect(ctx): if len(ctx.args) < 5: reply_text = "You haven't given a source to connect to! Example: 'connect discord token_here'" return reply_text result = ctx.args.split(" ", 2) if len(result) != 2: reply_text = "You haven't given either a source or your token! Example: 'connect discord token_here'" return reply_text to_source, token = result to_source = to_source.lower() if ctx.bot.source.name in to_source or to_source not in settings.get('bot_sources', []): reply_text = "You have given an invalid source! Example: 'connect discord token_here'" return reply_text reply_text = connect_token(ctx.user_id, token, to_source) if not reply_text: reply_text = ("Invalid token!" "\nSay MyWaifu on {} to get your token!".format(to_source.title())) return reply_text return reply_text
def run(overidden_settings={}, run_server=False): settings.merge(overidden_settings) urls = ( '{}'.format(settings.get('BASE_URL')), 'index', '{}results/(.*)/'.format(settings.get('BASE_URL')), 'results', '{}run/(.*)/'.format(settings.get('BASE_URL')), 'start_blast', '{}status/(.*)/'.format(settings.get('BASE_URL')), 'status', '{}sequence/(.*)/(.*)/'.format(settings.get('BASE_URL')), 'sequence', '{}multisequence/'.format(settings.get('BASE_URL')), 'multisequence', ) app = web.application(urls, globals()) if run_server: app.run() else: return app.wsgifunc()
def GET(self, identifier): web.header('Content-type', 'application/json') file_loc = "{0}{1}.xml".format(settings.get('BLAST_RESULTS_PATH'), identifier) qs = web.input() cutoff = qs.get('cutoff') with open(file_loc) as results: ''' if cutoff is not None: processed = process_blast_result(results.read(), cutoff=float(cutoff)) else: processed = process_blast_result(results.read()) results_page = render_template('results.html', settings = settings, results = processed, uuid = uuid.uuid4(), identifier = identifier, ) ''' return json.dumps({'active': False}) #, 'results': processed, 'results_page': results_page}) return json.dumps({'active': False, 'err': 'There has been an error'})
def waifu(ctx, gender=None, search_for=None, is_otp=False): """Get a random {OPTION}""" if ctx.command == "waifu" or gender == "waifu": list_name = "Waifu" end_tag = ["1girl", "solo"] else: list_name = "Husbando" end_tag = ["-1girl", "-genderbend", "1boy", "solo"] result = () path = os.path.join(ctx.bot.config_path, '{} List.yaml'.format(list_name)) if "video game" in ctx.args.lower() and list_name == "Waifu": char_list = yaml_to_list(path, "video game") else: char_list = yaml_to_list(path, list_name.lower()) # This is used so they can't get aroun dbeing limited with x cmd # Plus to the odd series to make people actually use other cmds 😠. ignore = ["high-school-dxd", "love-live", "love-live-sunshine" "aoki-hagane-no-arpeggio", "kantai-collection", "aikatsu", "akb0048", "idolmaster", "idolmaster-cinderella-girls"] matched = [] if search_for is None: search_for = ctx.args if len(search_for) >= 5 and slugify(search_for) not in ignore: result = filter_per_series(char_list, search_for, 4) if not result: result = random.choice(char_list) name = re.sub("[\(\[].*?[\)\]]", "", result[0]).strip() # Remove () and [] series = result[1].get('series') otp_image = result[1].get('otp image') if is_otp: return name, series, otp_image start_path = settings.get('image_location', os.path.join(os.path.realpath(__file__), 'images')) path_name = os.path.join(start_path, list_name, slugify(result[0])) end_tag.append(result[0].replace(" ", "_")) reply_text = "Your {} is {} ({})".format(list_name, name, series) media_args = {'tags': end_tag} reply_media = get_media(path=path_name, ctx=ctx, media_args=media_args) return reply_text, reply_media
def plugin_main(self, new_file): inode, file_path = new_file if bool('[iPhone]' in file_path) or bool('[iPad]' in file_path): return ext = path.splitext(file_path)[1][1:] filename = path.splitext(file_path)[0][:] #log.debug("filename:%s" % filename) #log.debug("ext:%s" % ext) #log.debug("file_path:%s" % file_path) """ Convert file name """ if '/iPhone' in file_path: trans_dir = settings.get('transcode','iPhone') #log.debug("trans_dir:%s" % trans_dir) filename = filename[len(trans_dir)+1:] if ext in self.EXT_AUDIO: trans_aud_file = path.join(trans_dir, '[iPhone]'+ filename +'.mp3') elif ext in self.EXT_VIDEO: trans_vid_file = path.join(trans_dir, '[iPhone]'+ filename +'.mp4') else: return elif '/iPad' in file_path: trans_dir = settings.get('transcode','iPad') #log.debug("trans_dir:%s" % trans_dir) filename = filename[len(trans_dir)+1:] if ext in self.EXT_AUDIO: trans_aud_file = path.join(trans_dir, '[iPad]'+ filename +'.mp3') elif ext in self.EXT_VIDEO: trans_vid_file = path.join(trans_dir, '[iPad]'+ filename +'.mp4') else: return else: #log.info("No transcoding for the wrong path.") return #log.debug("trans filename:%s" % filename) #log.debug("trans_aud_file:%s" % trans_aud_file) """ Transcoding Audio or Video by ffmpeg """ # Execute audio transcoding if ext in self.EXT_AUDIO: fnull = open(devnull, 'w') log.info("Audio Transcoding Start") command = ['ffmpeg', '-i', file_path, '-acodec', 'libmp3lame', '-ar', '48000', '-ab', '128k', '-ac', '2', trans_aud_file] call(command, shell = False, stdout = fnull, stderr = fnull) fnull.close() log.info("Audio Transcoding End") # Execute video transcdoing elif ext in self.EXT_VIDEO: return else: return self.push_back({'uid' : inode, 'module' : self.name})
'/site', 'site', '/page', 'page', '/page/add', 'edit_page', '/page/([^/]+)','edit_page', '/page/([^/]+)/delete','delete_page', '/page/([^/]+)/content', 'content', '/page/([^/]+)/content/add', 'edit_content', '/page/([^/]+)/content/(\d+)', 'edit_content', '/page/([^/]+)/content/(\d+)/delete', 'delete_content' ) admin_app = web.application(urls, locals()) store = web.session.DBStore(db, 'sessions') session = web.session.Session(admin_app, store, initializer={'logged_in': False}) render = web.template.render(settings.get('Settings','admin_templates'), base='layout') plain = web.template.render(settings.get('Settings','admin_templates')) def secure(f): def proxyfunc(self, *args, **kw): if session.logged_in: return f(self, *args, **kw) else: raise web.seeother("/login") return proxyfunc class login: login_form = form.Form( form.Textbox("username", description="Username"), form.Password("password", description="Password"), form.Button("submit", type="submit", description="Login") )
def run_dedupe(args, dataset): """Complete a single run of dedupe on the specified dataset.""" # read in the datasets, assuming two for record linkage input_files = dataset['input_files'] if len(input_files) != 2: parser.error('--dataset has != 2 input files') path = dataset['path'] f1 = dataset['input_files'][0] data_file_1 = f1['data_file'] field_map_1 = f1.get('field_map', {}) encoding_1 = f1.get('encoding', 'utf-8') input_file_1 = load_csv('%s/%s' % (path, data_file_1), encoding=encoding_1, field_map=field_map_1) f2 = dataset['input_files'][1] data_file_2 = f2['data_file'] field_map_2 = f2.get('field_map', {}) encoding_2 = f2.get('encoding', 'utf-8') input_file_2 = load_csv('%s/%s' % (path, data_file_2), encoding=encoding_2, field_map=field_map_2) # parse field definitions fields = [] for field_spec in dataset['fields']: field = {'field': field_spec['field'], 'type': field_spec['type']} if 'has_missing' in field_spec.keys(): field['has missing'] = field_spec['has_missing'] if 'corpus_file' in field_spec.keys(): corpus_path = '%s/%s' % (path, field_spec['corpus_file']) encoding = dataset.get('encoding', 'utf-8') field['corpus'] = corpus_generator(corpus_path, encoding=encoding) fields.append(field) logging.debug('Sampling') linker = dedupe.RecordLink(fields) # FIXME: 15000 is hard-coded and arbitrary, copied from dedupe example linker.sample(input_file_1, input_file_2, 15000) logging.debug('Loading match file') # read in the match file now so we can auto-label matches = load_csv('%s/%s' % (path, dataset['match_file']), list) match_count = 0 # create fast lookup for each set of matching identifiers from one # to the other, e.g. "if id2 in m1[id1]" match_set_1 = defaultdict(set) match_set_2 = defaultdict(set) match_id_1 = dataset['input_files'][0]['match_id'] match_id_2 = dataset['input_files'][1]['match_id'] for m in matches: match_count += 1 match_set_1[m[match_id_1]].add(m[match_id_2]) match_set_2[m[match_id_2]].add(m[match_id_1]) logging.debug('Auto-labeling') auto_label(linker, match_set_1, match_set_2, args.reliability, count=args.count) logging.debug('Training') linker.train() logging.debug('Matching') # FIXME: third param "0" is hard-coded linked_records = linker.match(input_file_1, input_file_2, 0) logging.debug('Reviewing linked records') linked_records_count = 0 correct_count = incorrect_count = 0 for cluster, score in linked_records: linked_records_count += 1 logging.debug('cluster %s, score %s' % (cluster, score)) is_correct = False id1, id2 = cluster r1 = input_file_1[id1] r2 = input_file_2[id2] if r2['id'] in match_set_1[r1['id']]: is_correct = True if r1['id'] in match_set_2[r2['id']]: is_correct = True if is_correct: correct_count += 1 logging.debug('CORRECT') else: incorrect_count += 1 logging.debug('INCORRECT') report = { 'match_count': match_count, 'linked_records_count': linked_records_count, 'correct_count': correct_count, 'incorrect_count': incorrect_count } # Generate a distinct filename for report, allowing for grouping report_path = '%s/%s-%s-%03d.json' % (settings.get('report_dir'), args.report_prefix, args.dataset, args.job_id) with open(report_path, 'w') as fp_report: json.dump(report, fp_report, indent=2) logging.info('Wrote report to %s' % report_path)