Advertisement
tonyabbottsears

IP Casanova Script (GUI v3.3)

Mar 22nd, 2014
8,918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 19.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Version 3.3:
  4. # added deep and shallow filter
  5. # moved login out of search function
  6. # fixed offset bug in original script
  7. # removed unnecessary wait condition
  8.  
  9. ################################################################################
  10. # IMPORTANT THINGS YOU SHOULD TOTALLY READ:
  11. #
  12. # Country codes: http://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements
  13. # Language codes: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
  14. # If there are multiple codes available, you want the 2-letter one.
  15. #
  16. # "Deep filter" will do a specific search for your filtered keywords and ensures
  17. # they will definitely not be viewed. It cannot be restricted to only those who
  18. # are online though, so select this if:
  19. # - you're also searching offline users
  20. # - you're filtering out a pretty obscure term (not "korea")
  21. # - you don't mind waiting a while for the script to build its blacklist
  22. #
  23. # Otherwise, the shallow filter just checks the "about me" snippet provided,
  24. # so some can easily slip through the cracks.
  25. #
  26. # The save button will save everything you have entered in the config window at
  27. # that time, including your password, in plaintext. So if you're the kind of
  28. # person who cares about that, make sure the password box is empty when you save.
  29. #
  30. # If you put in incorrect values, the script won't warn you, you just won't
  31. # get the results you want. At the moment anyway.
  32. ################################################################################
  33.  
  34. import time
  35. import sys
  36. import os
  37. import requests
  38. import re
  39. import random
  40. import getpass
  41. from Tkinter import *
  42. import tkFileDialog
  43. import ast
  44.  
  45. # We keep already visited profile in a file to avoid visiting
  46. # a profile multiple times on consecutive execution of this script
  47. # YOU CAN DELETE THIS FILE IF YOU WANT TO VISIT EVERYBODY ONCE AGAIN
  48. visitedUsersFilename = "users_visited.txt"
  49.  
  50. # Set this variable to True to output debug log,
  51. # or False for more concise output
  52. DEBUG = True
  53. ##
  54. ## END OF CONFIG VARIABLES
  55. ##
  56.  
  57. def login(s, user, pw):
  58.     payload = {'action': 'login',
  59.                'login': user,
  60.                'auto_login' : '0',
  61.                'password': pw}
  62.      
  63.     print "Logging in..."
  64.     s.get("http://www.interpals.net/")
  65.     r = s.post("http://www.interpals.net/login.php", data=payload)
  66.     if "<li>Authentication failed. Please try again." in r.text:
  67.         print "Login failed, check your details and try again"
  68.         exit()
  69.     print "Logged in: Starting the dance \o/"
  70.     time.sleep(2)
  71.    
  72. def search(s, url, mindel, maxdel, rundel, filtered_users, fterms):
  73.     offset1 = -20
  74.     offset2 = 0
  75.     sessioncount = 0
  76.     run_number = 1
  77.     min_delay = float(mindel)
  78.     max_delay = float(maxdel)
  79.     run_delay = float(rundel)
  80.     f = open(visitedUsersFilename, 'a+')
  81.     processedUsers = [line.strip() for line in f]
  82.     print "Already processed " + str(len(processedUsers)) + " users."
  83.  
  84.     while True:
  85.         runcount = 0                    
  86.         if DEBUG:
  87.             print "Fetching the search page..."
  88.         r = s.get(url + "&offset=%d&offset=%d" % (offset1, offset2))
  89.         data = r.text
  90.         for m in re.finditer('<b><a href=', data):
  91.             username = data[m.start()+13:m.start()+28]
  92.             if '?' in username:
  93.                 mesto = username.index('?')
  94.                 username = username[:mesto]
  95.             culoc = data.find("iso/16/", m.start())
  96.             cucode = data[culoc+7:culoc+9]
  97.             if len(fterms) > 0:
  98.                 # Run the shallow filter
  99.                 donotwant = False
  100.                 bioloc = data.find("sResTxtField", m.start())
  101.                 bioend = data.find("</div>", bioloc)
  102.                 for fil in fterms:
  103.                     filloc = data.find(fil, bioloc+14, bioend)
  104.                     if filloc != -1:
  105.                         print("Avoiding " + username + " due to their bio snippet")
  106.                         donotwant = True
  107.                 if donotwant:
  108.                     continue
  109.             if username not in processedUsers and username not in filtered_users:
  110.                 if DEBUG:
  111.                     print("Visiting profile of " + username + " from " + cucode + " (" + str(sessioncount) + ")")
  112.                 runcount += 1
  113.                 sessioncount += 1
  114.                 r = s.get("http://www.interpals.net/" + username)
  115.                 waitTime = random.randrange(min_delay*10, max_delay*10) / float(10)
  116.                 if DEBUG:
  117.                     print("Waiting " + str(waitTime) + "s")
  118.                 else:
  119.                     os.system('cls' if os.name=='nt' else 'clear')
  120.                     print('\rRun %d - Fetched %d users (%d total)' % (run_number, runcount, sessioncount))
  121.                 time.sleep(waitTime)
  122.                 processedUsers.append(username)
  123.                 f.write(username + "\n")
  124.             elif DEBUG and username in processedUsers:
  125.                 print("Already visited " + username)
  126.             elif DEBUG:
  127.                 print("Avoiding " + username + ", they're blacklisted")
  128.         run_number += 1
  129.         offset1=offset1+20
  130.         offset2=offset2+20
  131.         print ('Waiting (%d)s before next run (fetched %d users this run, %d total)\n' % (run_delay, runcount, sessioncount))
  132.         time.sleep(run_delay)
  133.  
  134.  
  135. def get_filtered_users(s, url, rundel):
  136.     offset1 = -20
  137.     offset2 = 0
  138.     runcount = 0
  139.     run_delay = float(rundel)
  140.     f = open(visitedUsersFilename, 'a+')
  141.     filtered_users = []
  142.     while True:
  143.         runcount = 0                    
  144.         if DEBUG:
  145.             print("Finding out who to avoid...")
  146.         r = s.get(url + "&offset=%d&offset=%d" % (offset1, offset2))
  147.         data = r.text
  148.        
  149.         numfound = data.find("Showing matches ")
  150.         endfound = data.find("</div>", numfound)
  151.         textfound = data[numfound+16:endfound]
  152.         print("Processing users " + textfound)
  153.         for m in re.finditer('<b><a href=', data):
  154.             username = data[m.start()+13:m.start()+28]
  155.             if '?' in username:
  156.                 mesto = username.index('?')
  157.                 username = username[:mesto]
  158.             if DEBUG:
  159.                 print("Blacklisting " + username + "...")
  160.             filtered_users.append(username)
  161.             runcount += 1
  162.         if runcount == 0:
  163.             print("Finished building blacklist!")
  164.             return filtered_users
  165.         else:
  166.             offset1=offset1+20
  167.             offset2=offset2+20
  168.             # Wait 3x as long as a courtesy, search goes down enough as is
  169.             print ('Waiting (%d)s before getting the next page of undesirables' % (run_delay * 3))
  170.             time.sleep(run_delay * 3)
  171.  
  172. """
  173. GUI SHIT INCOMING, LOOK AWAY IT'S HIDEOUS
  174. """
  175.  
  176. class Controller():
  177.     """Controls all GUI elements"""
  178.     def __init__(self, frame):
  179.         """
  180.        Sadly this giant mess of declarations can't be done on the same line
  181.        since that binds all the checkboxes to the same value
  182.        """
  183.         male = IntVar()
  184.         female = IntVar()
  185.         photo = IntVar()
  186.         online = IntVar()
  187.         af = IntVar()
  188.         asia = IntVar()
  189.         eu = IntVar()
  190.         na = IntVar()
  191.         oc = IntVar()
  192.         sa = IntVar()
  193.         email = IntVar()
  194.         snail = IntVar()
  195.         langex = IntVar()
  196.         friend = IntVar()
  197.         sluzza = IntVar()
  198.         relo = IntVar()
  199.         deep = IntVar()
  200.        
  201.         main_frame = Frame(frame)
  202.  
  203.  
  204.         top_frame = Frame(main_frame)
  205.         age_frame = Frame(top_frame)
  206.         Label(age_frame, text="Age").pack(side=LEFT, padx=10, pady=5)
  207.         tlowage = Entry(age_frame, width=5)
  208.         tlowage.pack(side=LEFT, anchor=E)
  209.         Label(age_frame, text="to").pack(side=LEFT, padx=10, pady=5)
  210.         thighage = Entry(age_frame, width=5)
  211.         thighage.pack(side=LEFT, anchor=E)
  212.         age_frame.pack()
  213.  
  214.         sex_frame = Frame(top_frame)
  215.         malebox = Checkbutton(sex_frame, text="Male", var=male)
  216.         malebox.pack(side=LEFT)
  217.         femalebox = Checkbutton(sex_frame, text="Female", var=female)
  218.         femalebox.pack(side=LEFT)
  219.         sex_frame.pack()
  220.        
  221.         bool_frame = Frame(top_frame)
  222.         photobox = Checkbutton(bool_frame, text="With photo only", var=photo)
  223.         photobox.pack(side=LEFT)
  224.         onlinebox = Checkbutton(bool_frame, text="Online only", var=online)
  225.         onlinebox.pack(side=RIGHT)
  226.         bool_frame.pack()
  227.  
  228.         top_frame.pack()
  229.        
  230.         left_frame = Frame(main_frame)
  231.        
  232.  
  233.         look_frame = Frame(left_frame)
  234.         Label(look_frame, text="Looking for").pack(pady=(0, 5))
  235.         emailbox = Checkbutton(look_frame, text="Email penpals", var=email)
  236.         emailbox.pack()
  237.         snailbox = Checkbutton(look_frame, text="Snail mail penpals", var=snail)
  238.         snailbox.pack()
  239.         langbox = Checkbutton(look_frame, text="Language exchange", var=langex)
  240.         langbox.pack()
  241.         friendbox = Checkbutton(look_frame, text="Friendship", var=friend)
  242.         friendbox.pack()
  243.         sluzzabox = Checkbutton(look_frame, text="Romance/flirting", var=sluzza)
  244.         sluzzabox.pack()
  245.         relobox = Checkbutton(look_frame, text="Relationship", var=relo)
  246.         relobox.pack()
  247.         look_frame.pack()
  248.  
  249.         left_frame.pack(side=LEFT)
  250.  
  251.         right_frame = Frame(main_frame)
  252.         country_frame = Frame(right_frame)
  253.         Label(country_frame, text="Countries").pack()
  254.         countryent = Entry(country_frame, width=15)
  255.         countryent.pack()
  256.         cbutt_frame = Frame(country_frame)
  257.         countrybox = Listbox(country_frame, width=20)
  258.         baddcount = Button(cbutt_frame, text="Add", command=lambda countrybox=countrybox: countrybox.insert(END, countryent.get()))
  259.         baddcount.pack(side=LEFT)
  260.         bremcount = Button(cbutt_frame, text="Remove", command=lambda countrybox=countrybox: countrybox.delete(ANCHOR))
  261.         bremcount.pack(side=RIGHT)
  262.         cbutt_frame.pack()
  263.        
  264.         countrybox.pack()
  265.         country_frame.pack(padx=5, pady=20, side=LEFT)
  266.  
  267.         filter_frame = Frame(right_frame)
  268.         Label(filter_frame, text="Filters").pack()
  269.         filterent = Entry(filter_frame, width=15)
  270.         filterent.pack()
  271.         fbutt_frame = Frame(filter_frame)
  272.         filterbox = Listbox(filter_frame, width=20, height=8)
  273.         baddfilter = Button(fbutt_frame, text="Add", command=lambda filterbox=filterbox: filterbox.insert(END, filterent.get()))
  274.         baddfilter.pack(side=LEFT)
  275.         bremfilter = Button(fbutt_frame, text="Remove", command=lambda filterbox=filterbox: filterbox.delete(ANCHOR))
  276.         bremfilter.pack(side=RIGHT)
  277.         deepbox = Checkbutton(filter_frame, text="Deep filter", var=deep)
  278.         deepbox.pack(side=BOTTOM)
  279.         fbutt_frame.pack()
  280.         filterbox.pack()
  281.         filter_frame.pack(padx=5, pady=20, side=RIGHT)
  282.  
  283.         lang_frame = Frame(right_frame)
  284.         Label(lang_frame, text="Languages").pack()
  285.         langent = Entry(lang_frame, width=15)
  286.         langent.pack()
  287.         lbutt_frame = Frame(lang_frame)
  288.         langbox = Listbox(lang_frame, width=20)
  289.         baddlang = Button(lbutt_frame, text="Add", command=lambda langbox=langbox: langbox.insert(END, langent.get()))
  290.         baddlang.pack(side=LEFT)
  291.         bremlang = Button(lbutt_frame, text="Remove", command=lambda langbox=langbox: langbox.delete(ANCHOR))
  292.         bremlang.pack(side=RIGHT)
  293.         lbutt_frame.pack()
  294.         langbox.pack()
  295.         lang_frame.pack(padx=5, pady=20, side=RIGHT)
  296.  
  297.        
  298.         right_frame.pack(side=RIGHT)
  299.  
  300.         mid_frame = Frame(main_frame)
  301.        
  302.         cont_frame = Frame(mid_frame)
  303.         Label(cont_frame, text="Only select continents or countries, not both").pack()
  304.         afbox = Checkbutton(cont_frame, text="Africa", var=af)
  305.         afbox.pack()
  306.         asbox = Checkbutton(cont_frame, text="Asia", var=asia)
  307.         asbox.pack()
  308.         eubox = Checkbutton(cont_frame, text="Europe", var=eu)
  309.         eubox.pack()
  310.         nabox = Checkbutton(cont_frame, text="North America", var=na)
  311.         nabox.pack()
  312.         ocbox = Checkbutton(cont_frame, text="Australia/Oceania", var=oc)
  313.         ocbox.pack()
  314.         sabox = Checkbutton(cont_frame, text="South America", var=sa)
  315.         sabox.pack()
  316.         cont_frame.pack()
  317.  
  318.         mid_frame.pack(side=RIGHT)
  319.  
  320.         main_frame.pack()
  321.         buttons = Frame(frame)
  322.         botent_frame = Frame(buttons)
  323.         user_frame = Frame(botent_frame)
  324.         Label(user_frame, text="Username").pack()
  325.         euser = Entry(user_frame, width=15)
  326.         euser.pack()
  327.         Label(user_frame, text="Password").pack()
  328.         epass = Entry(user_frame, width=15, show="*")
  329.         epass.pack()
  330.         user_frame.pack(side=LEFT, padx=30)
  331.         delay_frame = Frame(botent_frame)
  332.         Label(delay_frame, text="Min delay (views)").pack()
  333.         emindel = Entry(delay_frame, width=3)
  334.         emindel.insert(0, "1")
  335.         emindel.pack()
  336.         Label(delay_frame, text="Max delay (views)").pack()
  337.         emaxdel = Entry(delay_frame, width=3)
  338.         emaxdel.insert(0, "3")
  339.         emaxdel.pack()
  340.         Label(delay_frame, text="Delay between runs").pack()
  341.         erundel = Entry(delay_frame, width=3)
  342.         erundel.insert(0, "5")
  343.         erundel.pack()
  344.         delay_frame.pack(side=RIGHT)
  345.         botent_frame.pack()
  346.         # Proper OOP is for losers
  347.         bstart = Button(buttons, text="Start", command=lambda:self.prepare(
  348.             male.get(), female.get(), photo.get(), online.get(), af.get(),
  349.             asia.get(), eu.get(), na.get(), oc.get(), sa.get(), email.get(),
  350.             snail.get(), langex.get(), friend.get(), sluzza.get(), relo.get(),
  351.             tlowage.get(), thighage.get(), countrybox.get(0, END),
  352.             langbox.get(0, END), euser.get(), epass.get(), emindel.get(),
  353.             emaxdel.get(), erundel.get(), frame, filterbox.get(0, END),
  354.             deep.get()))
  355.         bstart.pack(side=LEFT, padx=10, pady=10, expand=True)
  356.         bload = Button(buttons, text="Load Preset", command=lambda:self.load(
  357.             male, female, photo, online, af, asia, eu, na, oc, sa, email,
  358.             snail, langex, friend, sluzza, relo, tlowage, thighage, countrybox,
  359.             langbox, euser, epass, emindel, emaxdel, erundel, filterbox, deep))
  360.         bload.pack(side=LEFT, padx=10, pady=10, expand=True)
  361.         bsave = Button(buttons, text="Save Preset", command=lambda:self.save(
  362.             male.get(), female.get(), photo.get(), online.get(), af.get(),
  363.             asia.get(), eu.get(), na.get(), oc.get(), sa.get(), email.get(),
  364.             snail.get(), langex.get(), friend.get(), sluzza.get(), relo.get(),
  365.             tlowage.get(), thighage.get(), countrybox.get(0, END),
  366.             langbox.get(0, END), euser.get(), epass.get(), emindel.get(),
  367.             emaxdel.get(), erundel.get(), filterbox.get(0, END), deep.get()))
  368.         bsave.pack(side=LEFT, padx=10, pady=10, expand=True)
  369.  
  370.         buttons.pack()
  371.  
  372.     def save(self, *args):
  373.         name = tkFileDialog.asksaveasfilename()
  374.         if name != "":
  375.             f = open(name, 'w+')
  376.             for a in args:
  377.                 f.write(str(a).rstrip()+"\n")
  378.        
  379.     def load(self, *args):
  380.         name = tkFileDialog.askopenfilename()
  381.         if name != "":
  382.             f = open(name, 'r')
  383.             counter = 0
  384.             entries = [16, 17, 20, 21, 22, 23, 24]
  385.             for line in f:
  386.                 if counter == 18 or counter == 19 or counter == 25:
  387.                     args[counter].delete(0, END)
  388.                     tup = ast.literal_eval(line)
  389.                     for e in tup:
  390.                         args[counter].insert(END, e)
  391.                 elif counter in entries:
  392.                     args[counter].delete(0, END)
  393.                     args[counter].insert(0, line.strip())
  394.                 else:
  395.                     args[counter].set(int(line))
  396.                 counter += 1
  397.            
  398.     def prepare(self, *args):
  399.         url = self.build_url(args, False)
  400.         frame = args[25]
  401.         frame.destroy()
  402.         s = requests.Session()
  403.         login(s, args[20], args[21])
  404.         if args[27] == 1:
  405.             filter_url = ""
  406.             filtered_users = []
  407.             if len(args[26]) > 0:
  408.                 filter_url = self.build_url(args, True)
  409.                 filtered_users = get_filtered_users(s, filter_url, args[24])
  410.             search(s, url, args[22], args[23], args[24], filtered_users, [])
  411.         else:
  412.             fterms = args[26]
  413.             search(s, url, args[22], args[23], args[24], [], fterms)
  414.  
  415.     def build_url(self, args, needs_filter):
  416.         # Try and get this clusterfuck into something workable
  417.         url = "http://www.interpals.net/search.php?todo=search&sort=last_login"
  418.         # What ages do we want?
  419.         url += "&age1=%s&age2=%s" % (args[16], args[17])
  420.         # Do we want dudes or ladies?
  421.         if args[0] == 1 and args[1] == 1:
  422.             url += "&sex[0]=FEMALE&sex[1]=MALE"
  423.         elif args[0] == 1:
  424.             url += "&sex[0]=MALE"
  425.         else:
  426.             url += "&sex[0]=FEMALE"
  427.         # Are we looking for people with just photos or who are online?
  428.         if args[2] == 1:
  429.             url += "&photo=1"
  430.         if args[3] == 1:
  431.             url += "&online=true"
  432.         else:
  433.             url += "&online=false"
  434.         # Are we looking for continents or countries? And which?
  435.         if len(args[18]) > 0:
  436.             url += "&countries%5B%5D=---"
  437.             countries = args[18]
  438.             for c in countries:
  439.                 url += "&countries[%d]=%s" % (countries.index(c), c.upper())
  440.         else:
  441.             # Warning: masterful code reuse ahead
  442.             counter = 0
  443.             if args[4] == 1:
  444.                 url += "&continents[%d]=AF" % counter
  445.                 counter += 1
  446.             if args[5] == 1:
  447.                 url += "&continents[%d]=AS" % counter
  448.                 counter += 1
  449.             if args[6] == 1:
  450.                 url += "&continents[%d]=EU" % counter
  451.                 counter += 1
  452.             if args[7] == 1:
  453.                 url += "&continents[%d]=NA" % counter
  454.                 counter += 1
  455.             if args[8] == 1:
  456.                 url += "&continents[%d]=OC" % counter
  457.                 counter += 1
  458.             if args[9] == 1:
  459.                 url += "&continents[%d]=SA" % counter
  460.                 counter += 1
  461.         # Any language preference?
  462.         if len(args[19]) > 0:
  463.             url += "&languages%5B%5D=---"
  464.             languages = args[19]
  465.             for l in languages:
  466.                 url += "&languages[%d]=%s" % (languages.index(l), l.upper())
  467.         # Do we care what they're looking for?
  468.         counter = 0
  469.         if args[10] == 1:
  470.             url += "&lfor[%d]=lfor_email" % counter
  471.             counter += 1
  472.         if args[11] == 1:
  473.             url += "&lfor[%d]=lfor_snail" % counter
  474.             counter += 1
  475.         if args[12] == 1:
  476.             url += "&lfor[%d]=lfor_langex" % counter
  477.             counter += 1
  478.         if args[13] == 1:
  479.             url += "&lfor[%d]=lfor_friend" % counter
  480.             counter += 1
  481.         if args[14] == 1:
  482.             url += "&lfor[%d]=lfor_flirt" % counter
  483.             counter += 1
  484.         if args[15] == 1:
  485.             url += "&lfor[%d]=lfor_relation" % counter
  486.             counter += 1
  487.         if needs_filter:
  488.             filters = args[26]
  489.             for f in filters:
  490.                 url += "&keywords=%s" % f
  491.         if DEBUG:
  492.             print("Built a search url successfully: " + url)
  493.         return url
  494.  
  495.  
  496. class CasaApp():
  497.     def __init__(self, master=None):
  498.         master.title("Casanova config v3.3")
  499.         self.controller = Controller(master)
  500.        
  501.  
  502. def main():
  503.     root = Tk()
  504.     app = CasaApp(root)
  505.     root.mainloop()
  506.  
  507. if  __name__ == '__main__':
  508.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement