Beispiel #1
0
def build_markdown():
    # Build the markdown in stages. Live matches first, then past matches
    markdown_template = ''
    if strafe.live_matches and strafe.live_match_stats:
        try:
            markdown_template = read('template/strafe_widget_md_template.txt')
            markdown_template = build_live_match(markdown_template)
            if strafe.past_matches:
                markdown_template = build_past_matches(markdown_template)
        except IOError:
            logging.exception('{} - IOError opening md template!'.format(
                datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    elif strafe.past_matches:
        try:
            markdown_template = read(
                'template/strafe_widget_md_nolive_template.txt')
            markdown_template = build_past_matches(markdown_template)
        except IOError:
            logging.exception('{} - IOError opening md template!'.format(
                datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

    # If the markdown template isn't empty, save a copy
    # to our cache and begin the upload process
    if markdown_template != '' and strafe.past_matches:
        save('app-cache/finished_markdown.txt', markdown_template)
        r.widget_markdown = markdown_template
        upload_widget()
Beispiel #2
0
def home():
    lines = file_manager.read()
    now = datetime.datetime.now()
    templateData = {
        'status': 'Online',
        'log': lines,
        'server_datetime': now.strftime('%b %d, %H:%Mhs')
    }
    if environ.get('AUTO_ENABLED') == 'True':
        templateData.update({
            'auto':
            True,
            'time':
            environ.get('HOUR') + ':' + environ.get('MINUTE'),
            'button_text':
            'Turn Off'
        })
    else:
        templateData.update({'auto': False, 'button_text': 'Turn On'})

    templateData.update({'is_watering': environ.get('IS_WATERING') == 'True'})
    templateData.update({
        'time_area_1': environ.get('TIME_AREA_1'),
        'time_area_2': environ.get('TIME_AREA_2')
    })

    return render_template('home.html', **templateData)
Beispiel #3
0
    def __init__(self, stylesheet=None):
        self.user_agent = config['GlobalOffensiveBot']['user_agent']
        self.client_id = config['GlobalOffensiveBot']['client_id']
        self.client_secret = config['GlobalOffensiveBot']['client_secret']
        self.username = config['GlobalOffensiveBot']['username']
        self.password = config['GlobalOffensiveBot']['password']
        self.subreddit = config['GlobalOffensiveBot']['subreddit']
        self.r = self.get_praw_instance()

        # Temporary instance variables due to no PRAW support
        # for adding/editing widgets at the time of writing
        self.access_token = self.get_access_token()
        self.oauth_headers = {
            "Authorization": "bearer {}".format(self.access_token),
            "User-Agent": self.user_agent
        }
        self.widget_name = config['widget']['name']
        self.all_widgets_endpoint = 'https://oauth.reddit.com/r/{}/api/widgets'.format(
            self.subreddit)
        self.widget_id, self.widget_image_data = self.get_widget_info()
        self.widget_endpoint = 'https://oauth.reddit.com/r/{}/api/widget/{}'.format(
            self.subreddit, self.widget_id)
        self.widget_images_s3 = 'https://oauth.reddit.com/r/{}/api/widget_image_upload_s3'.format(
            self.subreddit)
        self.widget_markdown = ''
        if stylesheet is None:
            self.stylesheet = read('app-cache/strafe_widget_css.txt')
        else:
            self.stylesheet = stylesheet
        self.widget_height = config['widget']['height']
        self.widget_kind = config['widget']['kind']
        self.widget_styles = config['widget']['styles']
        self.live_placeholder = config['widget']['placeholders']['live']
        self.past_placeholder = config['widget']['placeholders']['past']
Beispiel #4
0
def getProfile():
    global config_root

    if 'profile' in cached_returns and time(
    ) - cached_returns['profile']['updated'] > 60 * 2:
        return cached_returns['profile']['return']

    file_contents = file_manager.read(config_root + 'profile.txt')

    if file_contents == False:
        log.warning('No profile.txt file found, assuming default.')
        file_contents = 'default'
    else:
        file_contents = file_contents.strip()

    cached_returns['profile'] = {'updated': time(), 'return': file_contents}

    return file_contents
Beispiel #5
0
def read(relative_path):
    global config_path
    return file_manager.read(config_path + relative_path)
Beispiel #6
0
def online_positions():
    return file_manager.read()
Beispiel #7
0
def main():
    '''
	Main function including :
	 - Arg parser Generation
	 - Graph Generation
	 - Thesaurus Generation
	 - Optionnal thesaurus test
	 - Writting Thesaurus
	'''
    parser = argparse.ArgumentParser()
    parser.add_argument("data_file", help='A .outmalt data file')
    parser.add_argument("-t",
                        "--theory",
                        default=None,
                        help='A compare file in the correct format.')
    parser.add_argument("--thesaurus",
                        type=int,
                        default=1000,
                        help='The size of the thesaurus.')
    parser.add_argument("--absolute",
                        action='store_true',
                        help='Use absolute mode.')
    parser.add_argument("-v",
                        "--verbose",
                        action='store_true',
                        help='Activate maximum detail mode.')
    parser.add_argument(
        "-l",
        "--limit",
        type=int,
        default=1000000,
        help='The number of lexemes proceed before cleaning the graph.')
    parser.add_argument(
        "-m",
        "--minimum_limit",
        type=int,
        default=10,
        help=
        'The number of occurrences needed for not being deleted when cleaning.'
    )
    parser.add_argument(
        "-w",
        "--write",
        default=None,
        help='The path to the file where thesaurus will be written.')
    args = parser.parse_args(sys.argv[1:])

    content = splitter(file_manager.read(args.data_file))
    thesau = thesaurus(
        tree_creator.token_list(content, args.limit, args.minimum_limit,
                                args.verbose))
    print("Graph has been generated. It has", len(thesau.corpus),
          "nodes inside.")

    mode = 'r'
    if args.absolute:
        mode = 'a'
    result = thesau.usable({'NC'}, thesau.cosine, thesau.PMI, mode,
                           args.thesaurus, args.verbose)
    print("The thesaurus has been generated.")

    if args.theory is not None:
        c, p = correlation(
            generate_compare(splitter(file_manager.read(args.theory))), result)
        print("With a cover of", p, "%, there is a correlation score of", c)

    if args.write:
        with open(args.write, 'w') as file:
            json.dump(result, file)
    else:
        print(result)
Beispiel #8
0
    # latest version of the markdown.
    time.sleep(10)

# Get the different components of the sidebar, but only if there is something
# in the sidebar markdown for them to replace!
if '__DISCORDCOUNT__' in sidebar and settings['sidebar']['social'][
        'discord_enabled']:
    discord_count = community_metrics.getDiscordUsersMarkdown()
if '__COMMUNITY_METRICS__' in sidebar:
    # if not settings['sidebar']['social']['ts_enabled'] and not settings['sidebar']['social']['irc_enabled']:
    # communityMetricsMd = ''
    # else:
    #
    communityMetricsMd = community_metrics.buildMarkdown()
if '__LIVESCORETICKER__' in sidebar:
    strafe_md = file_manager.read('strafe/app-cache/finished_markdown.txt')
if '__LIVESTREAMS__' in sidebar:
    # Returns spritesheet path and markdown
    livestreams = livestream_feed.build()
if '__MATCHTICKER__' in sidebar:
    matchesMd = csgo_matchticker.buildMarkdown()
if '__UPCOMING_EVENTS__' in sidebar:
    upcomingEventsMd = upcoming_events.buildMarkdown()
if '__NOTICES__' in sidebar:
    noticesMd = notices.runAutoposterAndBuildMarkdown(r)
if '__MM_STATUS__' in sidebar or '__MM_STATUS_URL__' in sidebar:
    # Returns status string and url suffix
    mm = csgo_matchmaking.getStatus()

# Replace the placeholders with the retrieved values, or defaults if they
# were not retrieved