-
-
Save TauPan/9eb35eabd609145203741044f2665f14 to your computer and use it in GitHub Desktop.
Automatic SpamCop report validation with python mechanize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# adapted from https://gist.github.com/iMilnb/75d65d88ce649b1f191a | |
import ConfigParser | |
import mechanize | |
import os | |
CONFIG = os.environ.get('SPAMCOP_CONFIG', | |
os.path.expanduser('~/secret/spamcop-config.ini')) | |
config = ConfigParser.SafeConfigParser() | |
config.read(CONFIG) | |
br = mechanize.Browser() | |
br.set_handle_robots(False) | |
br.open("http://www.spamcop.net/") | |
br.select_form(nr=0) | |
br.form['username'] = config.get('spamcop', 'username') | |
br.form['password'] = config.get('spamcop', 'password') | |
br.submit() | |
has_report = True | |
while has_report is True: | |
try: | |
l = br.click_link(text='Report Now') | |
except: | |
has_report = False | |
print('No report found.') | |
break | |
br.open(l) | |
try: | |
br.select_form(name='sendreport') | |
except: | |
continue | |
print('Sending report for {0}'.format(br.form['reports'])) | |
# the following will possibly fill br with a new 'Report Now' link | |
br.submit(label='Send Spam Report(s) Now') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: reads username + password from [spamcop] section of ini file ~/secret/spamcop-config.ini