0

I'm very new to Azure and was able get as far as generating the following init.py file:

import datetime
import logging

import azure.functions as func

def main(mytimer: func.TimerRequest) -> None:

utc_timestamp = datetime.datetime.utcnow().replace(
    tzinfo=datetime.timezone.utc).isoformat()

HubspotIngest() #is this where my function goes? Send help pls.

if mytimer.past_due:
    logging.info('The timer is past due!')

logging.info('Python timer trigger function ran at %s', utc_timestamp)

Along with the associated function.json:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 0 * * *"
    }
  ]
}

but don't know where to input my code so Azure knows what to run when the timer triggers:

from numpy import dtype
import pandas as pd
import requests
import datetime

def HubspotIngest():
    df = pd.DataFrame()
    print(9)
    api_client = HubSpot(api_key= key)
    x = requests.get('link')
    data = x.json()

    for i in range(0, len(data['objects'])):
        Id = data['objects'][i]['id']
        sent = data['objects'][i]['publishDate']
        From = data['objects'][i]['fromName']
        subject = data['objects'][i]['subject']
        analytics.track('Newsletter', {'datasource': 'hubspot', 'timestamp': datetime.datetime.now(),'id': Id, 'sent':sent, 'from': From, 'subject': subject})
        df2 = {'datasource': 'hubspot', 'id': Id, 'sent':sent, 'from': From, 'subject': subject}
        df = dfappend(df1, ignore_index = True)

Thank you for your time!

1 Answer 1

2

If I understand correctly, you can put the code of HubspotIngest in __init__.py:

import datetime
import logging
from numpy import dtype
import pandas as pd
import requests
import datetime
import azure.functions as func


def main(mytimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    if mytimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function ran at %s', utc_timestamp)
    HubspotIngest()


def HubspotIngest():
    df = pd.DataFrame()
    print(9)
    api_client = HubSpot(api_key= key)
    x = requests.get('link')
    data = x.json()

    for i in range(0, len(data['objects'])):
        Id = data['objects'][i]['id']
        sent = data['objects'][i]['publishDate']
        From = data['objects'][i]['fromName']
        subject = data['objects'][i]['subject']
        analytics.track('Newsletter', {'datasource': 'hubspot', 'timestamp': datetime.datetime.now(),'id': Id, 'sent':sent, 'from': From, 'subject': subject})
        df2 = {'datasource': 'hubspot', 'id': Id, 'sent':sent, 'from': From, 'subject': subject}
        df = dfappend(df1, ignore_index = True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.