This is a work in progress. There will be more to come. Once the backend is finished, I'll add a frontend in Tk.
More to come, stay tuned.
#EvilZone.py
#
#Created by: Tech B.
#4/2/2012
#!/usr/local/bin/env python
import urllib, urllib2, cookielib
import re
class EvilZone:
"""Class used to interact with evilzone.org"""
def __init__(self,user,pas):
"""Create the opener to store cookies and login"""
login_data = {'user':user, 'passwrd':pas, 'cookielength':60}
self.opener = self.Opener('http://www.evilzone.org/index.php')
self.POST(self.opener,'http://www.evilzone.org/login2/', login_data)
def Opener(self,ref):
"""Creats an opener to store cookies,
and keep a referer to the site
Added headers to help spoof browser"""
cj = cookielib.CookieJar()
openr = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
openr.addheaders.append(('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB;
rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'))
openr.addheaders.append(('Accept', 'text/html,application/xhtml+xml'))
openr.addheaders.append(('Keep-Alive', '115'))
openr.addheaders.append(('Referer',ref))
return openr
def GET(self,opnr,url):
"""EZ GET method, notice to data option"""
get_req = opnr.open(url)
return get_req.read()
def POST(self,opnr,url,data):
"""data is a dictinary type like login_data"""
enData = urllib.urlencode(data)
get_req = opnr.open(url,enData)
return get_req.read()
def getUnread(self, opnr):
"""Get unread topics, return as a list of URLs"""
#search pattern
search = '<a href="(.*)\/\?topicseen">'
unread = self.GET(opnr, "http://www.evilzone.org/unread")
found = re.findall(search, unread)
#if link has more than one page to it, remove duplicates
found = [url for url in found if '</a>' not in url]
#sort urls for what I want to read
sorted_found = []
for url in found:
if "scripting-languages" in url:
sorted_found.append(url)
if "hacking-and-security" in url:
sorted_found.append(url)
if "tutorials" in url:
sorted_found.append(url)
if "code-library" in url:
sorted_found.append(url)
if "science" in url:
sorted_found.append(url)
return sorted_found
def main():
#Example
ez = EvilZone('techb','lolpass')
unread = ez.getUnread(ez.opener)
if unread != []:
for topic in unread:
print topic+"\n"
main()
Sorry about the newline madness. The forums want to add more newlines than what's there.