-
Notifications
You must be signed in to change notification settings - Fork 0
/
spammer.py
131 lines (101 loc) · 3.2 KB
/
spammer.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
###############################################################################
#
# 2015 (C) Kushara Singh
#
# Licensed under WTFPL#
# http://www.wtfpl.net/
#
# Author is nor liable for misuse; Use carefully!
#
###############################################################################
#
# A dumb script to spam a google form.
#
# What it can spam? (1)
#
# - Single page forms
# - The following controls :
# - text
# - textarea
# - select
# - radio
# - checkbox
#
# What it cannot spam?
#
# - Multi page forms
# - Forms that require login (duh!)
# - A google form which has stuff not mentioned in (1)
#
###############################################################################
import random
import string
import sys
import mechanize
from lxml import html
import requests
REVIEWCOUNTER = 0
def new_browser():
""" Returns a new mechanize browser instance """
browser = mechanize.Browser()
browser.set_handle_robots(False)
browser.set_handle_refresh(False)
return browser
def fill_form(form):
global REVIEWCOUNTER
form.controls[0].value = 'Ramon Lawrence'
form.controls[1].value = 'Sciences'
form.controls[2].value = reviewList[REVIEWCOUNTER]
REVIEWCOUNTER = REVIEWCOUNTER +1
#Spams the form with Ramon reviews
def spam_form(times = 1):
browser = new_browser()
total = times
while times:
""" Open form """
#URL OF THE GOOGLE FORM!!!!!!!!!!!!!!! (Change if testing)
browser.open('https://docs.google.com/forms/d/e/1FAIpQLSdQbEUg5-C9TskmUPMRimoj__OLkY7pP7bR60fe1XMGeJ5efA/viewform')
browser.form = list(browser.forms())[0]
""" Mess it up and submit"""
fill_form(browser.form)
browser.submit()
times -= 1
print "%d. Filled form" % (total - times)
# Returns a list of all reviews from rate my professor page. Replaces the first and last names with Ramon and Lawrence. :)
def getReviews(myProfURL):
returnList = []
page = requests.get(myProfURL)
tree = html.fromstring(page.content)
# Get First and Last name of stolen reviews
firstName = tree.xpath('//span[@class="pfname"]/text()')[0].strip()
lastName = tree.xpath('//span[@class="plname"]/text()')[0].strip()
reviews = tree.xpath('//p[@class="commentsParagraph"]/text()')
for r in reviews:
txt = r.strip() #remove /r/l and trailing blank spaces
txt = txt.replace(firstName,"Ramon")
txt = txt.replace(lastName,"Lawrence")
txt = txt.replace(firstName.upper(),"Ramon")
txt = txt.replace(lastName.lower(),"Lawrence")
txt = txt.replace("she","he")
txt = txt.replace("She","He")
returnList.append(txt)
return returnList
#Return number of rate my prof reviews (one per line)
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
if __name__ == "__main__":
if len(sys.argv) < 1:
print "run script as\n'python %s 'url' (in quotes) '\n" %(__file__)
exit()
#Rate my prof URL
url = sys.argv[1]
#Gets list of reviews to spam form with
reviewList = getReviews(url)
#Number of reviews that we have
times = len(reviewList)
#Submits votes for Ramon
spam_form(times)