-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
129 lines (125 loc) · 3.02 KB
/
example.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# %%
import json
import os
from dotenv import load_dotenv
import src.amplitude_data_wrapper.analytics_api as amp
# %%
load_dotenv()
api_key = os.getenv("AMPLITUDE_EU_PROD_KEY")
api_secret = os.getenv("AMPLITUDE_EU_PROD_SECRET")
test_api_key = os.getenv("AMPLITUDE_EU_TEST_KEY")
test_api_secret = os.getenv("AMPLITUDE_EU_TEST_SECRET")
email = os.getenv("email")
chart_id_eu = os.getenv("chart_id_eu")
example_id_eu = os.getenv("example_id_eu")
cohort_id_eu = os.getenv("cohort_id_eu")
# %%
# without proxy
r = amp.get_chart(
api_key=api_key, secret=api_secret, chart_id=chart_id_eu, region=1
) # region 1 is EU
r.status_code
# %%
r.json() # returns data as json
# %%
r = amp.get_chart(
secret=api_secret, api_key=api_key, chart_id=chart_id_eu, region=1
) # region 1 is EU
r.status_code
# %%
# with proxy
proxies = {"http": "http://myproxy.example.org/method"}
r = amp.get_chart(api_key, api_secret, chart_id_eu, region=1, proxy=proxies)
r.status_code # print status code
# %%
r.json() # print data as json
# %%
user = amp.find_user(user=example_id_eu, api_key=api_key, secret=api_secret, region=1)
user.text # print data
# %%
proxies = {"http": "http://myproxy.example.org/method"}
path = "data/cohortdata.csv"
url = ""
cohort = amp.get_cohort(
api_key,
api_secret,
cohort_id_eu,
filename=path,
props=1,
region=1,
proxy=proxies,
)
# %%
user_data = json.loads(user.text)
deleteme = amp.delete_user_data(
user["matches"][0]["amplitude_id"],
email=email,
api_key=api_key,
secret=api_secret,
region=1,
ignore_invalid_id=True,
delete_from_org=False,
)
deleteme.text
# %%
tobe_deleted = amp.get_deletion_jobs(
start="2022-06-01",
end="2022-07-01",
api_key=api_key,
secret=api_secret,
region=1,
)
tobe_deleted.text
# %%
start = "20220501T09"
end = "20220501T11"
data = amp.export_project_data(
start=start,
end=end,
api_key=api_key,
secret=api_secret,
filename="data/projectdata.zip",
region=1,
)
# %%
types = amp.get_all_event_types(api_key=test_api_key, secret=test_api_secret, region=1)
types.status_code # 200
types.text # prints data
# %%
# write as json file
with open("data/test_types.json", "w") as f:
json.dump(types.json(), f, ensure_ascii=False)
# %%
with open("data/test_types.json") as f:
_ = f.read()
_ = json.loads(_)
dd = _["data"]
# %%
event_types = []
for i in dd:
event_types.append(i["event_type"])
with open("data/test_event_names.json", "w") as f:
json.dump(event_types, f, ensure_ascii=False)
# %%
# slett event_type med api
dtype = amp.delete_event_type(
api_key=test_api_key, secret=test_api_secret, event_type="atque maxime ducimus"
)
dtype.status_code
# %%
# get an event with segments
our_event_dict = {
"event_type": "pageview",
"group_by": [{"type": "event", "value": "app"}, {"type": "event", "value": "team"}],
}
data = amp.get_event_segmentation(
api_key=api_key,
secret=api_secret,
start="20220601",
end="20220602",
event=our_event_dict,
metrics="uniques",
interval=1,
limit=1000,
)
# %%