Created
October 22, 2019 05:58
-
-
Save dajor/eb18d92a25ba657bbe0aae87798f6e0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import azure.functions as func | |
import os, io, crm, json | |
import pandas as pd | |
from sugarcrm.client import Client | |
def main(myblob: func.InputStream): | |
logging.info(f"Python blob trigger function processed blob \n" | |
f"Name: {myblob.name}\n" | |
f"Blob Size: {myblob.length} bytes") | |
file = myblob.read() | |
csvf = io.BytesIO(file) | |
csvf = csvf.getvalue().decode('UTF-8') | |
sniffer = csv.Sniffer() | |
cnt = sniffer.sniff(csvf) | |
logging.info (cnt.delimiter) | |
df = pd.read_csv(io.BytesIO(file), sep=cnt.delimiter, dtype=str) | |
client = Client('https://sg-python.demo.sugarcrm.eu', 'admin', '***') | |
results = [] | |
results = json.loads(df.to_json(orient='records')) | |
for item in results: | |
logging.info("Import") | |
#item['id'] = item['CONTRACT_ID'] | |
logging.info(json.dumps(item,indent=2)) | |
client.set_entry('Leads', item ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment