Author Topic: [python] EvilZone Class  (Read 1160 times)

0 Members and 1 Guest are viewing this topic.

Online techb

  • Evilzone Love Spreader
  • Global Moderator
  • King
  • *
  • Posts: 2031
  • Cookies: 256
  • Gender: Male
  • Aliens do in fact wear hats.
    • View Profile
    • Tech B. Blog
[python] EvilZone Class
« on: April 14, 2012, 02:57:41 am »
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.


Code: Python
  1.  
  2. #EvilZone.py
  3. #
  4. #Created by: Tech B.
  5. #4/2/2012
  6.  
  7.  
  8. #!/usr/local/bin/env python
  9.  
  10.  
  11. import urllib, urllib2, cookielib
  12. import re
  13.  
  14.  
  15. class EvilZone:
  16.     """Class used to interact with evilzone.org"""
  17.  
  18.  
  19.     def __init__(self,user,pas):
  20.         """Create the opener to store cookies and login"""
  21.  
  22.  
  23.         login_data = {'user':user, 'passwrd':pas, 'cookielength':60}
  24.         self.opener = self.Opener('http://www.evilzone.org/index.php')
  25.         self.POST(self.opener,'http://www.evilzone.org/login2/', login_data)
  26.  
  27.  
  28.     def Opener(self,ref):
  29.         """Creats an opener to store cookies,
  30.        and keep a referer to the site
  31.        Added headers to help spoof browser"""
  32.  
  33.  
  34.         cj = cookielib.CookieJar()
  35.         openr = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  36.         openr.addheaders.append(('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB;
  37.  
  38.  
  39. rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'))
  40.         openr.addheaders.append(('Accept', 'text/html,application/xhtml+xml'))
  41.         openr.addheaders.append(('Keep-Alive', '115'))
  42.         openr.addheaders.append(('Referer',ref))
  43.         return openr
  44.  
  45.  
  46.     def GET(self,opnr,url):
  47.         """EZ GET method, notice to data option"""
  48.  
  49.  
  50.         get_req = opnr.open(url)
  51.         return get_req.read()
  52.  
  53.  
  54.     def POST(self,opnr,url,data):
  55.         """data is a dictinary type like login_data"""
  56.  
  57.  
  58.         enData = urllib.urlencode(data)
  59.         get_req = opnr.open(url,enData)
  60.         return get_req.read()
  61.  
  62.  
  63.     def getUnread(self, opnr):
  64.         """Get unread topics, return as a list of URLs"""
  65.  
  66.  
  67.         #search pattern
  68.         search = '<a href="(.*)\/\?topicseen">'
  69.         unread = self.GET(opnr, "http://www.evilzone.org/unread")
  70.  
  71.  
  72.         found = re.findall(search, unread)
  73.         #if link has more than one page to it, remove duplicates
  74.         found = [url for url in found if '</a>' not in url]
  75.         #sort urls for what I want to read
  76.         sorted_found = []
  77.         for url in found:
  78.             if "scripting-languages" in url:
  79.                 sorted_found.append(url)
  80.             if "hacking-and-security" in url:
  81.                 sorted_found.append(url)
  82.             if "tutorials" in url:
  83.                 sorted_found.append(url)
  84.             if "code-library" in url:
  85.                 sorted_found.append(url)
  86.             if "science" in url:
  87.                 sorted_found.append(url)
  88.  
  89.  
  90.         return sorted_found
  91.  
  92.  
  93. def main():
  94.     #Example
  95.     ez = EvilZone('techb','lolpass')
  96.  
  97.  
  98.     unread = ez.getUnread(ez.opener)
  99.     if unread != []:
  100.         for topic in unread:
  101.             print topic+"\n"
  102.  
  103.  
  104. main()
  105.  


Sorry about the newline madness. The forums want to add more newlines than what's there.
« Last Edit: September 09, 2012, 10:15:46 pm by techb »

Offline LeXeL

  • NULL
  • Posts: 14
  • Cookies: 1
    • View Profile
Re: [python] EvilZone Class
« Reply #1 on: June 17, 2012, 06:04:31 am »
1 (") and the hall code is a mess

at the __init__() the first comment is measing a "

Online techb

  • Evilzone Love Spreader
  • Global Moderator
  • King
  • *
  • Posts: 2031
  • Cookies: 256
  • Gender: Male
  • Aliens do in fact wear hats.
    • View Profile
    • Tech B. Blog
Re: [python] EvilZone Class
« Reply #2 on: June 17, 2012, 06:09:28 am »
1 (") and the hall code is a mess

at the __init__() the first comment is measing a "


Like I said, posting code on this forum is kinda madness. A lot of editing went into getting it to show up almost correctly.

Online Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 5160
  • Cookies: 405
  • Gender: Male
  • Motherflipper
    • View Profile
    • My blog
Re: [python] EvilZone Class
« Reply #3 on: June 17, 2012, 10:47:51 am »
Interesting. Try and look into an SMF API. I'm not sure if SMF has one but if it does you would be better off like that I think.

 



Intern0t SoldierX SecurityOverride programisiai
Want to be here? Contact Ande, Bluechill or Kulverstukas on the forum or at IRC.