Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Version 3.3:
- # added deep and shallow filter
- # moved login out of search function
- # fixed offset bug in original script
- # removed unnecessary wait condition
- ################################################################################
- # IMPORTANT THINGS YOU SHOULD TOTALLY READ:
- #
- # Country codes: http://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements
- # Language codes: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
- # If there are multiple codes available, you want the 2-letter one.
- #
- # "Deep filter" will do a specific search for your filtered keywords and ensures
- # they will definitely not be viewed. It cannot be restricted to only those who
- # are online though, so select this if:
- # - you're also searching offline users
- # - you're filtering out a pretty obscure term (not "korea")
- # - you don't mind waiting a while for the script to build its blacklist
- #
- # Otherwise, the shallow filter just checks the "about me" snippet provided,
- # so some can easily slip through the cracks.
- #
- # The save button will save everything you have entered in the config window at
- # that time, including your password, in plaintext. So if you're the kind of
- # person who cares about that, make sure the password box is empty when you save.
- #
- # If you put in incorrect values, the script won't warn you, you just won't
- # get the results you want. At the moment anyway.
- ################################################################################
- import time
- import sys
- import os
- import requests
- import re
- import random
- import getpass
- from Tkinter import *
- import tkFileDialog
- import ast
- # We keep already visited profile in a file to avoid visiting
- # a profile multiple times on consecutive execution of this script
- # YOU CAN DELETE THIS FILE IF YOU WANT TO VISIT EVERYBODY ONCE AGAIN
- visitedUsersFilename = "users_visited.txt"
- # Set this variable to True to output debug log,
- # or False for more concise output
- DEBUG = True
- ##
- ## END OF CONFIG VARIABLES
- ##
- def login(s, user, pw):
- payload = {'action': 'login',
- 'login': user,
- 'auto_login' : '0',
- 'password': pw}
- print "Logging in..."
- s.get("http://www.interpals.net/")
- r = s.post("http://www.interpals.net/login.php", data=payload)
- if "<li>Authentication failed. Please try again." in r.text:
- print "Login failed, check your details and try again"
- exit()
- print "Logged in: Starting the dance \o/"
- time.sleep(2)
- def search(s, url, mindel, maxdel, rundel, filtered_users, fterms):
- offset1 = -20
- offset2 = 0
- sessioncount = 0
- run_number = 1
- min_delay = float(mindel)
- max_delay = float(maxdel)
- run_delay = float(rundel)
- f = open(visitedUsersFilename, 'a+')
- processedUsers = [line.strip() for line in f]
- print "Already processed " + str(len(processedUsers)) + " users."
- while True:
- runcount = 0
- if DEBUG:
- print "Fetching the search page..."
- r = s.get(url + "&offset=%d&offset=%d" % (offset1, offset2))
- data = r.text
- for m in re.finditer('<b><a href=', data):
- username = data[m.start()+13:m.start()+28]
- if '?' in username:
- mesto = username.index('?')
- username = username[:mesto]
- culoc = data.find("iso/16/", m.start())
- cucode = data[culoc+7:culoc+9]
- if len(fterms) > 0:
- # Run the shallow filter
- donotwant = False
- bioloc = data.find("sResTxtField", m.start())
- bioend = data.find("</div>", bioloc)
- for fil in fterms:
- filloc = data.find(fil, bioloc+14, bioend)
- if filloc != -1:
- print("Avoiding " + username + " due to their bio snippet")
- donotwant = True
- if donotwant:
- continue
- if username not in processedUsers and username not in filtered_users:
- if DEBUG:
- print("Visiting profile of " + username + " from " + cucode + " (" + str(sessioncount) + ")")
- runcount += 1
- sessioncount += 1
- r = s.get("http://www.interpals.net/" + username)
- waitTime = random.randrange(min_delay*10, max_delay*10) / float(10)
- if DEBUG:
- print("Waiting " + str(waitTime) + "s")
- else:
- os.system('cls' if os.name=='nt' else 'clear')
- print('\rRun %d - Fetched %d users (%d total)' % (run_number, runcount, sessioncount))
- time.sleep(waitTime)
- processedUsers.append(username)
- f.write(username + "\n")
- elif DEBUG and username in processedUsers:
- print("Already visited " + username)
- elif DEBUG:
- print("Avoiding " + username + ", they're blacklisted")
- run_number += 1
- offset1=offset1+20
- offset2=offset2+20
- print ('Waiting (%d)s before next run (fetched %d users this run, %d total)\n' % (run_delay, runcount, sessioncount))
- time.sleep(run_delay)
- def get_filtered_users(s, url, rundel):
- offset1 = -20
- offset2 = 0
- runcount = 0
- run_delay = float(rundel)
- f = open(visitedUsersFilename, 'a+')
- filtered_users = []
- while True:
- runcount = 0
- if DEBUG:
- print("Finding out who to avoid...")
- r = s.get(url + "&offset=%d&offset=%d" % (offset1, offset2))
- data = r.text
- numfound = data.find("Showing matches ")
- endfound = data.find("</div>", numfound)
- textfound = data[numfound+16:endfound]
- print("Processing users " + textfound)
- for m in re.finditer('<b><a href=', data):
- username = data[m.start()+13:m.start()+28]
- if '?' in username:
- mesto = username.index('?')
- username = username[:mesto]
- if DEBUG:
- print("Blacklisting " + username + "...")
- filtered_users.append(username)
- runcount += 1
- if runcount == 0:
- print("Finished building blacklist!")
- return filtered_users
- else:
- offset1=offset1+20
- offset2=offset2+20
- # Wait 3x as long as a courtesy, search goes down enough as is
- print ('Waiting (%d)s before getting the next page of undesirables' % (run_delay * 3))
- time.sleep(run_delay * 3)
- """
- GUI SHIT INCOMING, LOOK AWAY IT'S HIDEOUS
- """
- class Controller():
- """Controls all GUI elements"""
- def __init__(self, frame):
- """
- Sadly this giant mess of declarations can't be done on the same line
- since that binds all the checkboxes to the same value
- """
- male = IntVar()
- female = IntVar()
- photo = IntVar()
- online = IntVar()
- af = IntVar()
- asia = IntVar()
- eu = IntVar()
- na = IntVar()
- oc = IntVar()
- sa = IntVar()
- email = IntVar()
- snail = IntVar()
- langex = IntVar()
- friend = IntVar()
- sluzza = IntVar()
- relo = IntVar()
- deep = IntVar()
- main_frame = Frame(frame)
- top_frame = Frame(main_frame)
- age_frame = Frame(top_frame)
- Label(age_frame, text="Age").pack(side=LEFT, padx=10, pady=5)
- tlowage = Entry(age_frame, width=5)
- tlowage.pack(side=LEFT, anchor=E)
- Label(age_frame, text="to").pack(side=LEFT, padx=10, pady=5)
- thighage = Entry(age_frame, width=5)
- thighage.pack(side=LEFT, anchor=E)
- age_frame.pack()
- sex_frame = Frame(top_frame)
- malebox = Checkbutton(sex_frame, text="Male", var=male)
- malebox.pack(side=LEFT)
- femalebox = Checkbutton(sex_frame, text="Female", var=female)
- femalebox.pack(side=LEFT)
- sex_frame.pack()
- bool_frame = Frame(top_frame)
- photobox = Checkbutton(bool_frame, text="With photo only", var=photo)
- photobox.pack(side=LEFT)
- onlinebox = Checkbutton(bool_frame, text="Online only", var=online)
- onlinebox.pack(side=RIGHT)
- bool_frame.pack()
- top_frame.pack()
- left_frame = Frame(main_frame)
- look_frame = Frame(left_frame)
- Label(look_frame, text="Looking for").pack(pady=(0, 5))
- emailbox = Checkbutton(look_frame, text="Email penpals", var=email)
- emailbox.pack()
- snailbox = Checkbutton(look_frame, text="Snail mail penpals", var=snail)
- snailbox.pack()
- langbox = Checkbutton(look_frame, text="Language exchange", var=langex)
- langbox.pack()
- friendbox = Checkbutton(look_frame, text="Friendship", var=friend)
- friendbox.pack()
- sluzzabox = Checkbutton(look_frame, text="Romance/flirting", var=sluzza)
- sluzzabox.pack()
- relobox = Checkbutton(look_frame, text="Relationship", var=relo)
- relobox.pack()
- look_frame.pack()
- left_frame.pack(side=LEFT)
- right_frame = Frame(main_frame)
- country_frame = Frame(right_frame)
- Label(country_frame, text="Countries").pack()
- countryent = Entry(country_frame, width=15)
- countryent.pack()
- cbutt_frame = Frame(country_frame)
- countrybox = Listbox(country_frame, width=20)
- baddcount = Button(cbutt_frame, text="Add", command=lambda countrybox=countrybox: countrybox.insert(END, countryent.get()))
- baddcount.pack(side=LEFT)
- bremcount = Button(cbutt_frame, text="Remove", command=lambda countrybox=countrybox: countrybox.delete(ANCHOR))
- bremcount.pack(side=RIGHT)
- cbutt_frame.pack()
- countrybox.pack()
- country_frame.pack(padx=5, pady=20, side=LEFT)
- filter_frame = Frame(right_frame)
- Label(filter_frame, text="Filters").pack()
- filterent = Entry(filter_frame, width=15)
- filterent.pack()
- fbutt_frame = Frame(filter_frame)
- filterbox = Listbox(filter_frame, width=20, height=8)
- baddfilter = Button(fbutt_frame, text="Add", command=lambda filterbox=filterbox: filterbox.insert(END, filterent.get()))
- baddfilter.pack(side=LEFT)
- bremfilter = Button(fbutt_frame, text="Remove", command=lambda filterbox=filterbox: filterbox.delete(ANCHOR))
- bremfilter.pack(side=RIGHT)
- deepbox = Checkbutton(filter_frame, text="Deep filter", var=deep)
- deepbox.pack(side=BOTTOM)
- fbutt_frame.pack()
- filterbox.pack()
- filter_frame.pack(padx=5, pady=20, side=RIGHT)
- lang_frame = Frame(right_frame)
- Label(lang_frame, text="Languages").pack()
- langent = Entry(lang_frame, width=15)
- langent.pack()
- lbutt_frame = Frame(lang_frame)
- langbox = Listbox(lang_frame, width=20)
- baddlang = Button(lbutt_frame, text="Add", command=lambda langbox=langbox: langbox.insert(END, langent.get()))
- baddlang.pack(side=LEFT)
- bremlang = Button(lbutt_frame, text="Remove", command=lambda langbox=langbox: langbox.delete(ANCHOR))
- bremlang.pack(side=RIGHT)
- lbutt_frame.pack()
- langbox.pack()
- lang_frame.pack(padx=5, pady=20, side=RIGHT)
- right_frame.pack(side=RIGHT)
- mid_frame = Frame(main_frame)
- cont_frame = Frame(mid_frame)
- Label(cont_frame, text="Only select continents or countries, not both").pack()
- afbox = Checkbutton(cont_frame, text="Africa", var=af)
- afbox.pack()
- asbox = Checkbutton(cont_frame, text="Asia", var=asia)
- asbox.pack()
- eubox = Checkbutton(cont_frame, text="Europe", var=eu)
- eubox.pack()
- nabox = Checkbutton(cont_frame, text="North America", var=na)
- nabox.pack()
- ocbox = Checkbutton(cont_frame, text="Australia/Oceania", var=oc)
- ocbox.pack()
- sabox = Checkbutton(cont_frame, text="South America", var=sa)
- sabox.pack()
- cont_frame.pack()
- mid_frame.pack(side=RIGHT)
- main_frame.pack()
- buttons = Frame(frame)
- botent_frame = Frame(buttons)
- user_frame = Frame(botent_frame)
- Label(user_frame, text="Username").pack()
- euser = Entry(user_frame, width=15)
- euser.pack()
- Label(user_frame, text="Password").pack()
- epass = Entry(user_frame, width=15, show="*")
- epass.pack()
- user_frame.pack(side=LEFT, padx=30)
- delay_frame = Frame(botent_frame)
- Label(delay_frame, text="Min delay (views)").pack()
- emindel = Entry(delay_frame, width=3)
- emindel.insert(0, "1")
- emindel.pack()
- Label(delay_frame, text="Max delay (views)").pack()
- emaxdel = Entry(delay_frame, width=3)
- emaxdel.insert(0, "3")
- emaxdel.pack()
- Label(delay_frame, text="Delay between runs").pack()
- erundel = Entry(delay_frame, width=3)
- erundel.insert(0, "5")
- erundel.pack()
- delay_frame.pack(side=RIGHT)
- botent_frame.pack()
- # Proper OOP is for losers
- bstart = Button(buttons, text="Start", command=lambda:self.prepare(
- male.get(), female.get(), photo.get(), online.get(), af.get(),
- asia.get(), eu.get(), na.get(), oc.get(), sa.get(), email.get(),
- snail.get(), langex.get(), friend.get(), sluzza.get(), relo.get(),
- tlowage.get(), thighage.get(), countrybox.get(0, END),
- langbox.get(0, END), euser.get(), epass.get(), emindel.get(),
- emaxdel.get(), erundel.get(), frame, filterbox.get(0, END),
- deep.get()))
- bstart.pack(side=LEFT, padx=10, pady=10, expand=True)
- bload = Button(buttons, text="Load Preset", command=lambda:self.load(
- male, female, photo, online, af, asia, eu, na, oc, sa, email,
- snail, langex, friend, sluzza, relo, tlowage, thighage, countrybox,
- langbox, euser, epass, emindel, emaxdel, erundel, filterbox, deep))
- bload.pack(side=LEFT, padx=10, pady=10, expand=True)
- bsave = Button(buttons, text="Save Preset", command=lambda:self.save(
- male.get(), female.get(), photo.get(), online.get(), af.get(),
- asia.get(), eu.get(), na.get(), oc.get(), sa.get(), email.get(),
- snail.get(), langex.get(), friend.get(), sluzza.get(), relo.get(),
- tlowage.get(), thighage.get(), countrybox.get(0, END),
- langbox.get(0, END), euser.get(), epass.get(), emindel.get(),
- emaxdel.get(), erundel.get(), filterbox.get(0, END), deep.get()))
- bsave.pack(side=LEFT, padx=10, pady=10, expand=True)
- buttons.pack()
- def save(self, *args):
- name = tkFileDialog.asksaveasfilename()
- if name != "":
- f = open(name, 'w+')
- for a in args:
- f.write(str(a).rstrip()+"\n")
- def load(self, *args):
- name = tkFileDialog.askopenfilename()
- if name != "":
- f = open(name, 'r')
- counter = 0
- entries = [16, 17, 20, 21, 22, 23, 24]
- for line in f:
- if counter == 18 or counter == 19 or counter == 25:
- args[counter].delete(0, END)
- tup = ast.literal_eval(line)
- for e in tup:
- args[counter].insert(END, e)
- elif counter in entries:
- args[counter].delete(0, END)
- args[counter].insert(0, line.strip())
- else:
- args[counter].set(int(line))
- counter += 1
- def prepare(self, *args):
- url = self.build_url(args, False)
- frame = args[25]
- frame.destroy()
- s = requests.Session()
- login(s, args[20], args[21])
- if args[27] == 1:
- filter_url = ""
- filtered_users = []
- if len(args[26]) > 0:
- filter_url = self.build_url(args, True)
- filtered_users = get_filtered_users(s, filter_url, args[24])
- search(s, url, args[22], args[23], args[24], filtered_users, [])
- else:
- fterms = args[26]
- search(s, url, args[22], args[23], args[24], [], fterms)
- def build_url(self, args, needs_filter):
- # Try and get this clusterfuck into something workable
- url = "http://www.interpals.net/search.php?todo=search&sort=last_login"
- # What ages do we want?
- url += "&age1=%s&age2=%s" % (args[16], args[17])
- # Do we want dudes or ladies?
- if args[0] == 1 and args[1] == 1:
- url += "&sex[0]=FEMALE&sex[1]=MALE"
- elif args[0] == 1:
- url += "&sex[0]=MALE"
- else:
- url += "&sex[0]=FEMALE"
- # Are we looking for people with just photos or who are online?
- if args[2] == 1:
- url += "&photo=1"
- if args[3] == 1:
- url += "&online=true"
- else:
- url += "&online=false"
- # Are we looking for continents or countries? And which?
- if len(args[18]) > 0:
- url += "&countries%5B%5D=---"
- countries = args[18]
- for c in countries:
- url += "&countries[%d]=%s" % (countries.index(c), c.upper())
- else:
- # Warning: masterful code reuse ahead
- counter = 0
- if args[4] == 1:
- url += "&continents[%d]=AF" % counter
- counter += 1
- if args[5] == 1:
- url += "&continents[%d]=AS" % counter
- counter += 1
- if args[6] == 1:
- url += "&continents[%d]=EU" % counter
- counter += 1
- if args[7] == 1:
- url += "&continents[%d]=NA" % counter
- counter += 1
- if args[8] == 1:
- url += "&continents[%d]=OC" % counter
- counter += 1
- if args[9] == 1:
- url += "&continents[%d]=SA" % counter
- counter += 1
- # Any language preference?
- if len(args[19]) > 0:
- url += "&languages%5B%5D=---"
- languages = args[19]
- for l in languages:
- url += "&languages[%d]=%s" % (languages.index(l), l.upper())
- # Do we care what they're looking for?
- counter = 0
- if args[10] == 1:
- url += "&lfor[%d]=lfor_email" % counter
- counter += 1
- if args[11] == 1:
- url += "&lfor[%d]=lfor_snail" % counter
- counter += 1
- if args[12] == 1:
- url += "&lfor[%d]=lfor_langex" % counter
- counter += 1
- if args[13] == 1:
- url += "&lfor[%d]=lfor_friend" % counter
- counter += 1
- if args[14] == 1:
- url += "&lfor[%d]=lfor_flirt" % counter
- counter += 1
- if args[15] == 1:
- url += "&lfor[%d]=lfor_relation" % counter
- counter += 1
- if needs_filter:
- filters = args[26]
- for f in filters:
- url += "&keywords=%s" % f
- if DEBUG:
- print("Built a search url successfully: " + url)
- return url
- class CasaApp():
- def __init__(self, master=None):
- master.title("Casanova config v3.3")
- self.controller = Controller(master)
- def main():
- root = Tk()
- app = CasaApp(root)
- root.mainloop()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement