Skip to content

Commit

Permalink
Changed most fields to be ids instead of values, also added support f…
Browse files Browse the repository at this point in the history
…or inventory targeting
  • Loading branch information
marsan02 committed Jan 12, 2024
1 parent b0830b8 commit 2b03cd1
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 42 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.env

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Binary file modified __pycache__/main.cpython-311.pyc
Binary file not shown.
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def submit_campaign():
return campaigns.post_campaign(request,client)
elif request.method == 'PUT':
# Update a campaign
campaign_id=request.args['_id']
return campaigns.put_campaign(campaign_id,request.json,client)
campaign_id=request.args.get('_id')
return campaigns.put_campaign(campaign_id,request,client)
@app.route('/campaigns', methods=['GET'])
@requires_auth
def manage_campaigns():
Expand Down Expand Up @@ -63,7 +63,6 @@ def submit_creative():
@app.route('/creatives', methods=['GET'])
@requires_auth
def manage_creatives():
print(request.args)
return creatives.get_creative(client,request.args)

@app.route('/creatives/<creative_name>', methods=['GET', 'PUT', 'DELETE'])
Expand Down
Binary file modified services/__pycache__/campaign.cpython-311.pyc
Binary file not shown.
82 changes: 44 additions & 38 deletions services/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ def get_campaign(campaign_id,client):
else:
return jsonify({"message": "Campaign not found" }), 404

def put_campaign(campaign_id,update_data,client):
def put_campaign(campaign_id,request,client):
db = client['campaigns']
campaigns = db.campaigns
result = campaigns.update_one({"_id": campaign_id}, {"$set": updated_data})
campaign_id=ObjectId(campaign_id)
payload = prepare_data(request.get_json())[0]
result = campaigns.update_one({"_id": campaign_id}, {"$set": payload})
if result.matched_count:
print("updated")
return jsonify({"message": "Campaign updated"})
else:
print("error)")
return jsonify({"message": "Campaign not found"}), 404

def delete_campaign(campaign_name,client):
Expand All @@ -39,50 +43,15 @@ def list_all_campaigns(client):
for item in all_campaigns_with_id:
print(item)
item["_id"] = str(item["_id"])
print(all_campaigns_with_id)
return jsonify(all_campaigns_with_id)

def post_campaign(request,client):
db = client['campaigns']
campaigns = db.campaigns
print("Submitting Campaign")
try:
# Extract form data
data = request.get_json()
campaign_name = data['campaign_name']
ad_types = data['ad_types']
creatives = data['creatives'].split(',')
device_types = data['device_types']
geography = data['geography']
inventory_type = data['inventory_type']
revenue_per_day = int(data['revenue_per_day'])
state = data['state']
total_budget = int(data['total_budget'])
start_date = data['start_date']
end_date = data['end_date']
goal_type = data['goal_type']
goal_value= data['goal_value']

# Create the data payload in the required format
payload = [{
"ad_types": ad_types,
"campaign_name": campaign_name,
"creatives": creatives,
"device_types": device_types,
"flight_dates": {
"start": start_date,
"end": end_date
},
"geography": geography,
"inventory_type": inventory_type,
"revenue_per_day": revenue_per_day,
"state": state,
"total_budget": total_budget,
"goal_type":goal_type,
"goal_value":goal_value
}]
print(payload)
campaign_data = payload
campaign_data = prepare_data(request.get_json())
try:
campaigns.insert_one(campaign_data[0])
return jsonify({"message": "Campaign added"}), 201
Expand All @@ -94,3 +63,40 @@ def post_campaign(request,client):
# Handle exceptions
print(e)
return str(e), 500

def prepare_data(data):
# Extract form data
campaign_name = data['campaign_name']
ad_types = data['ad_types']
creatives = data['creatives']
device_types = data['device_types']
geography = data['geography']
inventory_type = data['inventory_type']
revenue_per_day = int(data['revenue_per_day'])
state = data['state']
total_budget = int(data['total_budget'])
start_date = data['start_date']
end_date = data['end_date']
goal_type = data['goal_type']
goal_value= data['goal_value']
inventory = data['inventory']
# Create the data payload in the required format
payload = [{
"ad_types": ad_types,
"campaign_name": campaign_name,
"creatives": creatives,
"device_types": device_types,
"flight_dates": {
"start": start_date,
"end": end_date
},
"geography": geography,
"inventory_type": inventory_type,
"revenue_per_day": revenue_per_day,
"state": state,
"total_budget": total_budget,
"goal_type":goal_type,
"goal_value":goal_value,
"inventory":inventory
}]
return payload
Binary file modified utils/__pycache__/geo_api.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion utils/geo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize():

def check_ip(geoip_reader,ip_address):
response = geoip_reader.country(ip_address)
print(response)
(response)
country = response.country.name
return country

Expand Down

0 comments on commit 2b03cd1

Please sign in to comment.