-
Notifications
You must be signed in to change notification settings - Fork 0
/
gig_submitter.py
145 lines (116 loc) · 4.12 KB
/
gig_submitter.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from pandas import DataFrame, read_csv
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
import time
import datetime, xlrd
# LOAD PYTHON FILES TO HANDLE EACH GIG LISTING SERVICE
import email_bandsintown
import send_to_strumsy
import send_to_songkick
import send_to_dubsado
# BE SURE TO UPDATE YOUR LOGIN.PY FILE WITH CREDENTIALS
import settings
headless = settings.headless
testMode = settings.testMode
doSTR = settings.doSTR
doSK = settings.doSK
doBIT = settings.doBIT
doDUB = settings.doDUB
xls_file = settings.login['xls_file']
gigList = []
#*************************************
def fixTime (aDateTime):
return '{:%H:%M}'.format(aDateTime)
#*************************************
###########################################
#START DOING STUFF
#clear the text output
for i in range(5):
print "\n."
print "*********************"
print "RUNNING GIG SUBMITTER"
print "*********************\n"
if testMode:
print "RUNNING IN TEST MODE: Browser will display (not headless) and gigs won't actually be submitted."
# Send email to BANDSINTOWN FIRST
if doBIT:
try:
print "need to fix BIT upload"
#email_bandsintown.send_email()
except: print "Problem sending EMAIL to BANDSINTOWN"
else:
print "SKIPPED BANDSINTOWN (as per settings.py)"
print "\n\n\n"
#IF NEITHER doSK NOR doSTR
if not doSK and not doSTR and not doDUB:
print "SKIPPING SUBMISSIONS TO SONGKICK, DUBSADO AND STRUMSY (as per settings.py)"
#Load array with gig info at least STR or SK
else:
print "NOW WILL SEND TO ",
if doSK:
print "SONGKICK ",
if doSTR:
print "STRUMSY ",
if doDUB:
print "DUBSADO "
print "\n.\n.\n."
# READ XLS FILE WITH GIG INFO
print "READING : " + xls_file
df = pd.read_excel(xls_file)
# ITERATE OVER THE SPREADSHEET ROWS AND LOAD INTO TEMPORARY VARIABLES,
# PUT THOSE INTO DICTIONARY FOR SONGKICK ANDOR STRUMSY
print "IMPORTING GIG #",
for i in df.index:
gigDate = df['Date'][i].date().strftime('%m/%d/%Y') #convert to proper date format
gigTimeStart = fixTime(df['Time'][i])
gigVenue = df['Venue'][i].replace(u"\u2018", "'").replace(u"\u2019", "'") #replace some ugly apostrophes
gigCity = df['City'][i]
gigState = df['State'][i]
gigDetails = df['Description'][i].replace(u"\u2018", "'").replace(u"\u2019", "'")
gigAge = "".replace(u"\u2018", "'").replace(u"\u2019", "'")
print i + 1, #give user an idea of how many gigs are being imported from spreadsheet
# add to list (for Strumsy and songkick)
aGig = [gigDate, gigTimeStart, gigVenue, gigCity, gigState, gigDetails, gigAge]
gigList.append(aGig)
# SET HEADLESS OPTION FOR ALL FUTURE BROWSERS
options = webdriver.ChromeOptions()
# incognito window
options.add_argument("--incognito")
# maximize window
#options.add_argument("--kiosk")
if headless:
options.add_argument('headless')
# MAKE A BROWSER
browser = webdriver.Chrome(chrome_options = options) #replace with .Firefox(), or with the browser of your choice
#browser.implicitly_wait(10)
if doSK:
#try:
send_to_songkick.submit_gig_to_songkick(gigList, browser)
#except:
#print "Problem submitting to SONGKICK"
else:
print "SKIPPING SONGKICK"
if doDUB:
#try:
send_to_dubsado.submit_gig(gigList, browser)
#except:
#print "Problem submitting to Dubsado"
else:
print "SKIPPING DUBSADO"
if doSTR:
#try:
send_to_strumsy.submit_gig_to_strumsy(gigList, browser)
#except:
#print "Problem submitting to STRUMSY"
else:
print "SKIPPING STRUMSY"
# close the browser window
browser.quit()