/
app.py
executable file
·64 lines (49 loc) · 1.81 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
import os
from gevent import monkey
import faulthandler
if not os.environ.get('SERVER_SOFTWARE', '').startswith('gunicorn'):
print('Monkey patching manually')
monkey.patch_all()
print('Enable faulthandler')
faulthandler.enable()
print('Is monkey patched?', monkey.is_anything_patched())
from flask import Flask, render_template, jsonify, request
from google.ads.googleads.client import GoogleAdsClient
CUSTOMER_ID = '9713819907'
LOGIN_CUSTOMER_ID = '6123296949' # if using a client account under a manager account, the manager account id goes here
DEVELOPER_TOKEN = 'RzTH0-qWDgGAaFj2W-NhqA'
CLIENT_ID = '626110127825.apps.googleusercontent.com'
CLIENT_SECRET = 'a16w9mNY-7Qex1Ft6W05j3Nf'
REFRESH_TOKEN = '1//06XJzNwLJUnXBCgYIARAAGAYSNwF-L9IrhPPaq4F8YANMIFyPLT408mFHGUzuIzkFgJNnJGeXDLTqrzZKEhmS_E9ENCghiGn5tjw'
app = Flask(__name__)
@app.get('/')
def index():
return render_template('index.html')
@app.get('/test')
def test():
credentials = {
'developer_token': DEVELOPER_TOKEN,
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'refresh_token': REFRESH_TOKEN,
'use_proto_plus': True,
}
if LOGIN_CUSTOMER_ID:
credentials['login_customer_id'] = LOGIN_CUSTOMER_ID
client = GoogleAdsClient.load_from_dict(credentials)
query = """
SELECT metrics.cost_micros
FROM age_range_view
WHERE segments.date DURING LAST_30_DAYS
"""
google_ads_service = client.get_service('GoogleAdsService')
result = google_ads_service.search_stream(customer_id=CUSTOMER_ID, query=query)
for batch in result:
for row in batch.results:
pass
i = request.args.get('i')
print(f'request {i} OK')
return jsonify({})
if __name__ == '__main__':
app.run(debug=True)