-
Notifications
You must be signed in to change notification settings - Fork 1
/
batch.py
28 lines (25 loc) · 1.08 KB
/
batch.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
from datetime import datetime, timedelta
import calendar
import event_export
import settings
def add_months(sourcedate,months):
month = sourcedate.month - 1 + months
year = int(sourcedate.year + month / 12 )
month = month % 12 + 1
day = min(sourcedate.day,calendar.monthrange(year,month)[1])
return datetime(year,month,day)
if __name__ == '__main__':
from_date = datetime.strptime(raw_input("From Date: "), "%Y-%m-%d")
to_date = datetime.strptime(raw_input("To Date: "), "%Y-%m-%d")
while True:
end_date = add_months(from_date,1)
if to_date < end_date : end_date = to_date
try:
api_secret = settings.mixpanel['api_secret']
output_file = "mixpanel_{0}_{1}_{2}.json".format(settings.mixpanel['project'], from_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d"))
event_export.mixpanel(from_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d"), output_file, api_secret)
except Exception as e:
continue
if to_date == end_date:
break
from_date = end_date