Skip to content

Commit

Permalink
Update campaign grid to load even without reporting data.
Browse files Browse the repository at this point in the history
  • Loading branch information
marsan02 committed Feb 25, 2024
1 parent 85c806f commit cf128c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
15 changes: 7 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ def process_campaign_monitoring(*args, **kwargs):
"filters": []
}
reporting_data = reporting.run_report(buyer_id, payload['dimensions'], payload['metrics'], payload['filters'])

# Create a lookup for campaign reporting data
reporting_lookup = {report['campaign_id']: report for report in reporting_data}
reporting_lookup = {report.get('campaign_id'): report for report in reporting_data}

stitched_data = []
if status == 200:
Expand Down Expand Up @@ -115,7 +114,7 @@ def campaigns_service(*args, **kwargs):
elif request.method == 'PUT':
return campaigns.put_mysql(request.args['id'],request.json,buyer_id,mysql_conn)
elif request.method == 'DELETE':
return campaigns.get_mysql(request.args['id'],buyer_id,mysql_conn)
return campaigns.delete_mysql(request.args['id'],buyer_id,mysql_conn)
elif request.method == 'POST':
return campaigns.post_mysql(request.json,buyer_id,mysql_conn)

Expand All @@ -128,13 +127,13 @@ def advertisers_service(*args, **kwargs):
if buyer_id:
buyer_id=int(buyer_id)
if request.method == 'GET':
result = advertisers.get_mysql(request.args,request.args.get('id'),1,mysql_conn)
result = advertisers.get_mysql(request.args,request.args.get('id'),buyer_id,mysql_conn)
elif request.method == 'PUT':
result = advertisers.put_mysql(request.args['id'],request.json,1,mysql_conn)
result = advertisers.put_mysql(request.args['id'],request.json,buyer_id,mysql_conn)
elif request.method == 'DELETE':
result = advertisers.delete_mysql(request.args['id'],1,mysql_conn)
result = advertisers.delete_mysql(request.args['id'],buyer_id,mysql_conn)
elif request.method == 'POST':
result = advertisers.post_mysql(request.json,1,mysql_conn)
result = advertisers.post_mysql(request.json,buyer_id,mysql_conn)
return result

@app.route('/deals', methods=['POST','GET', 'PUT', 'DELETE'])
Expand Down Expand Up @@ -196,7 +195,7 @@ def buyers_service(*args, **kwargs):
elif request.method == 'PUT':
result= buyers.put_mysql(request.args['id'],request.json,buyer_id,mysql_conn)
elif request.method == 'DELETE':
result= buyers.delete(request.args['id'],buyer_id)
result= buyers.delete_mysql(request.args['id'],buyer_id,mysql_conn)
elif request.method == 'POST':
result= buyers.post_mysql(request.json,buyer_id,mysql_conn)
return result
Expand Down
14 changes: 9 additions & 5 deletions services/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ def run_report(buyer_id,dimensions, metrics, filters):
account = os.environ.get('SNOWFLALE_ACCOUNT')
table = os.environ.get('SNOWFLAKE_REPORTING_TABLE')
# Connect to Snowflake
conn = snowflake.connector.connect(
user=user,
password=password,
account=account
)
try:
conn = snowflake.connector.connect(
user=user,
password=password,
account=account
)
except Exception as e:
print(f"Error: {e}")
return {}
if buyer_id:
query = f'WHERE 1=1 AND buyer_id={buyer_id}'
else:
Expand Down

0 comments on commit cf128c2

Please sign in to comment.