示例#1
0
def fbook_it(logger, matchinfo_dic_, img_list_, season_id, match_id):
    """ facebook post """
    # pylint: disable=R0914
    logger.debug('fbook_it()')

    # load rebound and break interval from config file
    (_consumer_key, _consumer_secret, _oauth_token, _oauth_token_secret,
     fb_token_file) = _config_load(LOGGER)

    # get access token
    token_dic = json_load(fb_token_file)
    access_token = None
    if 'access_token' in token_dic:
        access_token = token_dic['access_token']

    # message test used in post
    match_date = uts_to_date_utc(matchinfo_dic_['date_uts'], '%d.%m.%Y')
    message = 'Hier ein paar Charts zum Spiel {0} gg. {1}. vom {2} (Endstand: {3}).\nMehr unter https://hockeygraphs.dynamop.de/matchstatistics/{4}/{5} ...'.format(
        matchinfo_dic['home_team__shortcut'].upper(),
        matchinfo_dic['visitor_team__shortcut'].upper(), match_date,
        matchinfo_dic['result_full'], season_id, match_id)

    # list of groups to be published
    group_list = ['1799006236944342']

    # post to facebook group
    facebook_post(logger, group_list, message, img_list_, access_token)
示例#2
0
def twitter_it(logger, matchinfo_dic_, img_list_, season_id, match_id_):
    """ twitter post """
    # pylint: disable=R0914
    logger.debug('twitter_it()')

    tags = '#{0}vs{1} #{0}{1} #bot1337'.format(
        matchinfo_dic_['home_team__shortcut'].upper(),
        matchinfo_dic_['visitor_team__shortcut'].upper())

    # load rebound and break interval from config file
    (consumer_key, consumer_secret, oauth_token, oauth_token_secret,
     _fb_token_file) = _config_load(LOGGER)

    chart_list = ['Charts', 'bunte Bildchen', 'Grafiken', 'Chartz']
    match_date = uts_to_date_utc(matchinfo_dic_['date_uts'], '%d.%m.%Y')
    text_initial = 'Hier ein paar {2} zum Spiel {0} gg. {1}. vom {5} (Endstand: {6}).\nMehr unter https://hockeygraphs.dynamop.de/matchstatistics/{3}/{4} ...'.format(
        matchinfo_dic_['home_team__shortcut'].upper(),
        matchinfo_dic['visitor_team__shortcut'].upper(),
        random.choice(chart_list), season_id, match_id_, match_date,
        matchinfo_dic_['result_full'])
    text_reply = 'Und noch die Eiszeiten pro Spieler pro Drittel und in Über- und Unterzahl... {0}'.format(
        tags)

    # LogIn
    twitter_uploader = twitter_login(logger, consumer_key, consumer_secret,
                                     oauth_token, oauth_token_secret,
                                     'upload.twitter.com')
    # upload images
    id_list = twitter_image_upload(logger, twitter_uploader, img_list_)

    # add shotmap if existing
    if id_list[3]:
        id_string = '{0},{1},{2},{3}'.format(id_list[0], id_list[1],
                                             id_list[2], id_list[3])
        id_string_reply = '{0},{1},{2},{3}'.format(id_list[4], id_list[5],
                                                   id_list[6], id_list[7])
    else:
        id_string = '{0},{1},{2}'.format(id_list[0], id_list[1], id_list[2])
        id_string_reply = '{0},{1},{2},{3}'.format(id_list[3], id_list[4],
                                                   id_list[5], id_list[6])

    twitter_api = twitter_login(logger, consumer_key, consumer_secret,
                                oauth_token, oauth_token_secret)
    tweet_text = '{0} {1}'.format(text_initial, tags)
    result = twitter_api.statuses.update(status=tweet_text,
                                         media_ids=id_string)
    id_str = result['id']
    result = twitter_api.statuses.update(status=text_reply,
                                         media_ids=id_string_reply,
                                         in_reply_to_status_id=id_str)
def chatterchart_create(logger, ctitle, csubtitle, ismobile, events_dic,
                        plotband_list):
    """ create chatter chart """
    logger.debug('chatterchart_create()')

    variable_dic = variables_get(ismobile)

    data_list = []
    x_list = []

    cnt = 0
    for _uts, event in sorted(events_dic.items()):

        # we need to count the amount of tweets to calculate the chartsize
        cnt += 1

        # on the fly timestamp for x-axis
        timestamp = uts_to_date_utc(date_to_uts_utc(event['created_at']),
                                    '%H:%M')

        if 'text_raw' in event:
            timestamp = uts_to_date_utc(
                int(date_to_uts_utc(event['created_at']) + 3600), '%H:%M')
            # this is a regular event
            text_shorten = textwrap.shorten(
                event['text_raw'], variable_dic['timeline_wrap_length'])
            data_list.append({
                'x': cnt,
                'name': timestamp,
                'aname': '@{0}'.format(event['name_alternate']),
                'scolor': twitter_color,
                'label': text_shorten,
                'description': event['text_raw'],
                'dataLabels': {
                    'style': {
                        'fontSize': variable_dic['timeline_font_size']
                    }
                }
            })
        else:
            # this is a goal
            data_list.append({
                'x': cnt,
                'name': timestamp,
                'aname': '#bot1337',
                'scolor': chart_color3,
                'color': event['color'],
                'label': event['name_alternate'],
                'dataLabels': {
                    'color': event['color'],
                    'style': {
                        'fontSize': variable_dic['timeline_font_size'],
                        'fontWeight': 'bold'
                    }
                }
            })

        x_list.append({'x': cnt, 'name': timestamp})

    # charthight depends on number of tweets - need to be calculated
    chart_height = variable_dic['ticker_startval'] + (
        cnt * variable_dic['ticker_multiplier'])

    chart_options = {
        'chart': {
            'type': 'timeline',
            'height': '{0}%'.format(chart_height),
            'inverted': 1,
            'zoomType': 'x',
            #'alignTicks': 0,
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'plotOptions': {
            'timeline': {
                'dataLabels': {
                    'align': 'left',
                    'distance': variable_dic['timeline_distance'],
                    'alternate': 0
                }
            }
        },
        'tooltip': {
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span style="color: {point.scolor}"><b>{point.aname}</b></span><br>{point.description}',
        },
        'xAxis': {
            'categories': x_list,
            'visible': 1,
            'tickWidth': 0,
            'tickInterval': 3,
            'showFirstLabel': 1,
            'showLastLabel': 1,
            'lineWidth': 0,
            'labels': {
                'enabled': 1,
                'style': {
                    'fontSize': variable_dic['timeline_font_size']
                }
            },
            'plotBands': plotband_list,
        },
        'yAxis': {
            'gridLineWidth': 3,
            'title': '',
            'startOnTick': 0,
            'endOnTick': 0,
            'labels': {
                'enabled': 0
            },
            'width': 50
        },
        'colors': [chart_color6],
        'series': [{
            'dataLabels': {
                'allowOverlap': 1,
                'format': '{point.label}',
                'borderWidth': 0
            },
            'data': data_list
        }]
    }
    return chart_options
示例#4
0
        TOURNAMENT_ID = season_get(LOGGER, 'id', SEASON_ID, ['tournament'])

    # get team_list
    TEAM_DIC = list2dic(
        LOGGER, list(team_list_get(LOGGER, None, None,
                                   ['team_id', 'shortcut'])), 'shortcut')

    with DelAppHelper(DEVICE_ID, DEBUG) as del_app_helper:
        # get matches for a season
        game_dic = del_app_helper.games_get(TOURNAMENT_ID)
        for match in game_dic:
            if match['homeTeam'] in TEAM_DIC and match['guestTeam'] in TEAM_DIC:
                # skip past matches
                if UTS_NOW <= match['dateTime']:
                    data_dic = {
                        'home_team_id': TEAM_DIC[match['homeTeam']]['team_id'],
                        'visitor_team_id':
                        TEAM_DIC[match['guestTeam']]['team_id'],
                        'date_uts': match['dateTime'],
                        'date': uts_to_date_utc(match['dateTime'], '%Y-%m-%d'),
                        'season_id': SEASON_ID,
                        'match_id': match['gameNumber']
                    }
                    (match_id, created) = match_add(LOGGER, 'match_id',
                                                    match['gameNumber'],
                                                    data_dic)
                    if created:
                        LOGGER.debug('match_created({0})'.format(match_id))
                    else:
                        LOGGER.debug('match_updated({0})'.format(match_id))
示例#5
0
                                       file_size))

        if img_list:
            if not FAKE:

                # update database and set post flag - we do this before posting to avoid loops due to exceptions
                match_add(LOGGER, 'match_id', match_id, {'tweet': True})

                # twitterle
                twitter_it(LOGGER, matchinfo_dic, img_list, SEASON_ID,
                           match_id)
                # fb-post
                fbook_it(LOGGER, matchinfo_dic, img_list, SEASON_ID, match_id)

            # temporary email
            MATCH_DATE = uts_to_date_utc(matchinfo_dic['date_uts'], '%d.%m.%Y')
            MESSAGE = 'Hier ein paar Charts zum Spiel {0} gg. {1}. vom {2} (Endstand: {3}).\nMehr unter https://hockeygraphs.dynamop.de/matchstatistics/{4}/{5} ...'.format(
                matchinfo_dic['home_team__shortcut'].upper(),
                matchinfo_dic['visitor_team__shortcut'].upper(), MATCH_DATE,
                matchinfo_dic['result_full'], SEASON_ID, match_id)
            SUBJECT = '{0} vs {1}'.format(
                matchinfo_dic['home_team__shortcut'],
                matchinfo_dic['visitor_team__shortcut'])
            send_mail('*****@*****.**',
                      '*****@*****.**',
                      SUBJECT,
                      MESSAGE,
                      img_list,
                      server=settings.EMAIL_HOST,
                      username=settings.EMAIL_HOST_USER,
                      password=settings.EMAIL_HOST_PASSWORD)
示例#6
0
    (DEBUG, TOKEN, FILENAME) = arg_parse()

    # initialize logger
    LOGGER = logger_setup(DEBUG)

    # load rebound and break interval from config file
    (APP_NAME, APP_ID, APP_SECRET) = _config_load(LOGGER)

    # unix timestamp
    UTS = uts_now()

    URL = "https://graph.facebook.com/v10.0/oauth/access_token"

    data_dic = {
        'grant_type': 'fb_exchange_token',
        'client_id': APP_ID,
        'client_secret': APP_SECRET,
        'fb_exchange_token': TOKEN
    }

    try:
        req = requests.get(URL, params=data_dic)
        result = req.json()
        # add current uts and date
        result['uts'] = UTS
        result['DATE_HUMAN'] = uts_to_date_utc(UTS)
        # store result
        json_store(FILENAME, result)
    except BaseException as err_:
        print(err_)