-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape.py
215 lines (175 loc) · 6.74 KB
/
scrape.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
from bs4 import BeautifulSoup
import requests
import requests.exceptions
import random
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from fbcreds import app_id, app_secret
from twilio.twiml.messaging_response import MessagingResponse
from twilio.rest import Client
# Find these values at https://twilio.com/user/account
account_sid = "AC3e1252b3f55741e9dfeb3fb4ef66d88e"
auth_token = "2e89e4f761bee93067348899cc5e6493"
client = Client(account_sid, auth_token)
# scope = ['https://spreadsheets.google.com/feeds']
# creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
# client = gspread.authorize(creds)
# sheet = client.open("commitDB").sheet1
# sheetList = sheet.get_all_values()
def ping(u):
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
page = requests.get(u)
return page
def extendToken(short_token):
# requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# app_id = ''
# app_secret = ''
u = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&' + 'client_id=' + app_id + '&client_secret=' + app_secret + '&fb_exchange_token=' + short_token
r = requests.get(u)
print(r)
resp = r.json()
print(resp)
longtoken = resp['access_token']
print(resp['access_token'])
#{'access_token': 'EAACyc2hNZCsABAA7t8mRlg3ADekZBTHZA1fw5misTnwczPZBftobR9pTSXrlih9zYi775vaPdjgZABpHYehX927sNZCBsOwatTW5rZANIZCCucsK52oZCiATT9r6Wl3sTTaMAzObXgh75Ft3lbr7jLtXemqgt0bZCp9ruiD2ZAzyksVSgZDZD', 'token_type': 'bearer', 'expires_in': 5179108}
return longtoken
def sendSMS(from_num):
### get phone number
cnt = 0
for subscriber in subscriber_list:
from_num = '+'+subscriber[0]
now = datetime.datetime.now()
now = now.replace(second=0, microsecond=0)
if len(subscriber[1]) < 2:
lastsent = now - datetime.timedelta(days=7)
lastsent = lastsent.replace(second=0, microsecond=0)
test = datetime.datetime.strptime(subscriber[1],"%Y-%m-%d %H:%M:%S") + datetime.timedelta(days=7)
# print('Found +17733541500')
# print(from_num)
if test < now:
message = client.api.account.messages.create(to=from_num, from_="+16172497881", body=reminder)
### need to add row to subscriber list so we can update the correct row
sheet.update_cell(subscriber[5], 12, now)
sheet.update_cell(subscriber[5], 13, now)
cnt += 1
print('send_sms sent "'+ str(reminder) +'" to '+ str(cnt) + ' numbers')
return page
# def getUserFromRef(refcode):
# #requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
# name = getRow(refcode);
# #name = sheetList[row][1]
# return name
# def getRow(uid):
# rlen = len(sheetList)
# clen = len(sheetList[0])
# peeps = {}
# cnt = 0
# namerow = 0
# new = True
# for row in range(rlen):
# if row == 0:
# continue
# cnt += 1
# zerocell = sheetList[row][0]
# #print "uid zerocell",uid,zerocell
# if str(uid) == str(zerocell):
# #print "uid zerocell",uid,zerocell
# new = False
# #print "new is ",new
# break
# if(new):
# row = cnt+2
# #sheet.update_cell(row, 2, "unknown user") # pos message
# name = "Team COMM!T"
# else:
# row = cnt
# name = sheetList[row][1]
# return name
# def writeMessageToDB(message):
# # use creds to create a client to interact with the Google Drive API
# row = 2
# #row = getRow(uid)
# sheet.update_cell(row, 4, message) # pos message
# return message
# def writeMessageToDB2(message):
# # use creds to create a client to interact with the Google Drive API
# row = 2
# #row = getRow(uid)
# sheet.update_cell(row, 5, message) # pos message
# return message
# def writeUserToDB(message):
# # use creds to create a client to interact with the Google Drive API
# ### save longtoken to db along with uid and whatever else ###
# rlen = len(sheetList)
# clen = len(sheetList[0])
# peeps = {}
# for row in range(rlen):
# if row == 0:
# continue
# tmp = []
# for i in range(1,4):
# tmp.append(sheetList[row][i])
# peeps[sheetList[row][0]] = tmp
# cnt = 0
# new = True
# for key, val in peeps.items():
# cnt += 1
# if key == message:
# new = False
# break
# #cnt+1 is current user, cnt+2 will write new line
# row = 0
# if(new):
# row = cnt+2
# else:
# row = cnt+1
# sheet.update_cell(row, 1, message) # pos message
# return 'success'
# def writeAll(json_dict):
# uid = json_dict['uid']
# longToken = json_dict['longToken']
# friends = ''
# timeStamp = datetime.datetime.now()
# message1 = ""
# message2 = ""
# row = getRow(uid)
# sheet.update_cell(row, 2, timeStamp)
# sheet.update_cell(row, 3, longToken)
# sheet.update_cell(row, 8, friends)
# sheet.update_cell(row, 4, message1)
# sheet.update_cell(row, 5, message2)
# return 'writeAll succeeded'
# get persistent layer as list of lists
# def pLayer():
# # Find a workbook by name and open the first sheet
# # Make sure you use the right name here.
# # use creds to create a client to interact with the Google Drive API
# scope = ['https://spreadsheets.google.com/feeds']
# creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
# client = gspread.authorize(creds)
# sheet = client.open("VoteBot App").sheet1
# # Extract and print all of the values
# #list_of_vals = sheet.get_all_values()
# return sheet
# def people():
# # use creds to create a client to interact with the Google Drive API
# scope = ['https://spreadsheets.google.com/feeds']
# creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
# client = gspread.authorize(creds)
# sheet = client.open("commitDB").sheet1
# sheetList = sheet.get_all_values()
# rlen = len(sheetList)
# clen = len(sheetList[0])
# peeps = {}
# for row in range(rlen):
# if row == 0:
# continue
# tmp = []
# for i in range(1,10):
# tmp.append(sheetList[row][i])
# peeps['+' + sheetList[row][0]] = tmp
# return peeps
# peoples = people()
# print(peoples)
# print('Done!')