示例#1
0
def getNewsPerProfile(event, context):

    print("event", event)
    # get profileID
    profileID = event['profileID']
    # get last check timestamp
    config = ConfigHandler(profileID)
    lastCheckTimestamp = config.getLastCheckTimestmap()
    webhookURL = config.getWebhookURL()
    # print(lastCheckTimestamp)
    # print(config.getProfileConfig())
    # mark new timestamp
    # now = datetime.now() - timedelta(days = 30)
    now = datetime.now()
    newLastCheckTimestmap = now.isoformat()

    ## publish start statement
    publishToWebHook(
        "{\"Content\":\"/md **Daily " + config.getProfileConfig()['profile'] +
        " news**\"}", webhookURL)

    # is this a test
    if 'isTest' in event and event['isTest'] is True:
        print("Testing flow")
        testFrom = datetime.now() - timedelta(
            days=event['testBackDay'] if 'testBackDay' in event else 5)
        newFeeds = getNewFeeds(profileID, testFrom.isoformat(), isTest=True)
        # publish an end statement
        publishToWebHook(
            "{\"Content\":\"/md *Stay classy " +
            config.getProfileConfig()['profile'] + "!*\"}", webhookURL)
        return True

    # fool proof TODO refactor me
    newFeeds = getNewFeeds(profileID, lastCheckTimestamp, isTest=False)

    # update last check timestamp
    updateLastCheckTimestamp(profileID, newLastCheckTimestmap)

    # publish an end statement
    publishToWebHook(
        "{\"Content\":\"/md *Stay classy " +
        config.getProfileConfig()['profile'] + "!*\"}", webhookURL)

    return True
def getNews(event, context):

    # get last check timestamp
    config = ConfigHandler(profile)
    lastCheckTimestamp = config.getLastCheckTimestmap()
    print(lastCheckTimestamp)

    # save new feeds
    ## publish start statement
    publishToWebHook("{\"Content\":\"/md **Daily " + profile + " news**\"}")
    newFeeds = getNewFeeds(profile, lastCheckTimestamp)

    # mark new timestamp
    # now = datetime.now() - timedelta(days = 30)
    now = datetime.now()
    newLastCheckTimestmap = now.isoformat()
    # update last check timestamp
    # updateLastCheckTimestamp(newLastCheckTimestmap)

    # publish an end statement
    publishToWebHook("{\"Content\":\"/md *Stay classy " + profile + "!*\"}")

    return True