I'm working on a script, see here:
from pysnap import Snapchat
import time
usnlist = raw_input('Enter file name: ')
s = Snapchat()
def filter(username, password):
s.login(username, password)
with open (usnlist, 'r') as file:
for line in file:
ok = False
while not ok:
try:
resp = s.add_friend(line.rstrip("\n"))
if 'object' in resp.keys():
# 'object' is contained within resp as a key
if resp['object']['type']:
# type is 1
with open ('private.txt', 'a') as f: f.write(resp['object']['name']+"\n")
print line.rstrip("\n") + "'s",
print "privacy settings are set to: FRIENDS"
else:
# type is 0
with open ('n-private.txt', 'a') as f: f.write(resp['object']['name']+"\n")
print line.rstrip("\n") + "'s",
print "privacy settings are set to: EVERYONE"
s.delete_friend(line)
else:
# no object in resp, so it's an invalid username
print line.rstrip("\n") + " is not a valid username"
ok = True
except:
time.sleep(5)
print "SNAPCHAT SERVER OVERLOAD - HOLD ON."
username = raw_input('Enter username: ')
password = raw_input('Enter password: ')
filter(username, password)
What I want now is be able to input a value lets call it n
And when I input n
the bot scrapes only every n
line.
For example. N = 2
.
The bot now only scrapes and inputs every second username from the list.
I came up with some stuff, like adding [0::2] to: resp = s.add_friend(line.rstrip("\n"))
Resulting in: resp = s.add_friend(line[0::2].rstrip("\n"))
But that did not work, bot went straight to print "SNAPCHAT SERVER OVERLOAD - HOLD ON."
Without checking any names.
I got the idea here:
http://stackoverflow.com/questions/18155682/gathering-every-other-string-from-list-line-from-file
But the info given was not enough for me to get this to work. And I use python 2.7.8
I wish there was just a way to tell python: "Get every n
line in file"
Because that is basically what I am looking for.
If someone could help that'd be great!