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

0 Members and 1 Guest are viewing this topic.

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
[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) [Select]

#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.
« Last Edit: September 09, 2012, 10:15:46 pm by techb »
>>>import this
-----------------------------

Offline LeXeL

  • /dev/null
  • *
  • Posts: 12
  • 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 "

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
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.
>>>import this
-----------------------------

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • 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.