-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awin-sales.60s.py
53 lines (42 loc) · 1.9 KB
/
awin-sales.60s.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
#!/usr/bin/python
# <xbar.title>Awin Sales Summary</xbar.title>
# <xbar.version>1.0</xbar.version>
# <xbar.author>Paul Schoenmakers</xbar.author>
# <xbar.author.github>pschoenmakers</xbar.author.github>
# <xbar.desc>Displays your sales for today on the AWIN platform. Perfect for AWIN publishers.</xbar.desc>
# <xbar.dependencies>python</xbar.dependencies>
# <xbar.image>https://github.com/pschoenmakers/xbar-awin/blob/main/awin-sales-xbar-screenshot.jpg?raw=true<</xbar.image>
# <xbar.abouturl>https://github.com/pschoenmakers</xbar.abouturl>
import urllib2
import json
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
from datetime import datetime, time
today = datetime.today().strftime('%Y-%m-%d')
# Insert your publisherid and accesstoken below.
# See https://wiki.awin.com/index.php/API_authentication
# with info how to obtain your API accessToken.
pubid = "YOUR-PUBLISHER-ID"
accessToken = "YOUR-API-ACCESSTOKEN"
region = "de"
timezone = "Europe/Berlin"
response = urllib2.urlopen("https://api.awin.com/publishers/" + pubid + "/reports/advertiser?startDate=" + today +"&endDate=" + today + "&timezone=" + timezone + "®ion=" + region + "&accessToken=" + accessToken)
json_data = json.loads(response.read())
clicks = 0
commission = 0
salesnumber = 0
if json_data:
for item in json_data:
clicks = clicks + item['clicks']
commission = commission + item['totalComm']
salesnumber = salesnumber + item['totalNo']
print ("{} {} - {} clicks - {} sales".format(commission,item['currency'],clicks,salesnumber))
# Disable these lines below to only show the stats summary
# if you have a long list of advertisers the dropdown wouldn't make sense.
print("---")
for item in json_data:
print("{}: {} {} - {} clicks - {} sales".format(item['advertiserName'],item['totalComm'],item['currency'],item['clicks'],item['totalNo']))
else:
print("No clicks reported for today")