PDA

Просмотр полной версии : как запустить скрипт написанный на Python ?


-tatarin-
25.02.2010, 17:50
Нашел в инете скрипт приглашения в друзья всех членов определенной группы вконтакте, но не знаю как запустить его, помогите пжл! Вот скрипт:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by Nuclear Worm
#
#
# Vkontakte friends adder #
# Version 0.1.a.1
#

import os, sys, time, re, logging, sqlite3, urllib, urllib2, cookielib
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
VERSION='0.1.a.1'
COOKIEFILE = '/tmp/cookies1.lwp'
LOG_FILENAME = '/tmp/dbg.log'
logging.basicConfig(filename=LOG_FILENAME, filemode = 'w', level=logging.DEBUG,)

class PostCommand:
def __init__(self, url, req = None):
self.request = req
self.headers = ''
self.url = url

def perform(self):
cj = cookielib.LWPCookieJar()
if os.path.isfile(COOKIEFILE): cj.load(COOKIEFILE)
url_retr = urllib2.build_opener(urllib2.HTTPCookieProcessor(c j))
self.res = url_retr.open(self.url, self.request).read()
cj.save(COOKIEFILE)
logging.debug("Got to PostCommand request = %s, url = %s"%(self.request, self.url))
#self.res = urllib.urlopen(self.url, self.request).read()
logging.debug("Got result = %s"%self.res)

class GetCommand:
def __init__(self, url):
self.headers = ''
self.url = url
def perform(self):
cj = cookielib.LWPCookieJar()
if os.path.isfile(COOKIEFILE): cj.load(COOKIEFILE)
url_retr = urllib2.build_opener(urllib2.HTTPCookieProcessor(c j))
self.res = url_retr.open(self.url).read()
cj.save(COOKIEFILE)
logging.debug("Got to GetCommand url = %s"%(self.url))
#self.res = urllib.urlopen(self.url).read()
logging.debug("Got result = %s"%self.res)

class Vkontakte:
def __init__(self, mail, password):
self.mail = mail
self.password = password

def login(self):
request = 'op=a_login_attempt&email=' + self.mail + '&pass=' + self.password +'&expire=0'
req = PostCommand('http://vkontakte.ru/login.php', request)
req.perform()
my_id = re.compile('good(\d+)')
logging.debug("Reply from login:\n" + req.res)
if "failed" in req.res: return "Error! Check your login/pass!"
else:
myid = my_id.search(req.res).groups()[0]
return myid

class Group:
def __init__(self, group_id):
self.group_id = group_id

def find(self, datafile = None):
if datafile: self.datafile = datafile
else:
print "No datafile to store your friends"
sys.exit(1)
gp = GetCommand('http://vkontakte.ru/search.php?group=' + self.group_id)
gp.perform()
logging.debug("Reply from login:\n" + gp.res)
sum = re.compile('<strong>.* (\d+) .*\.</strong>')
all_those = sum.search(gp.res).groups()[0]
logging.debug("Sum of all users in group:\n" + all_those)
friends = extract_id(gp.res)
add_to_file(self.datafile, friends)
time.sleep(1)
for i in range(1, int(all_those)/10 + 1):
gp = GetCommand('http://vkontakte.ru/search.php?&group=' + self.group_id + '&o=0&st=' + str(i*10))
gp.perform()
friends = extract_id(gp.res)
add_to_file(self.datafile, friends)
time.sleep(1)
return sum


class Friend:
def __init__(self):
pass
def add(self, datafile = None, limit = None, message = None):
if datafile: self.datafile = datafile
else: pass
if limit: self.limit = limit
else: self.limit = 20000000
if message: self.message = message
else: self.message=''
df = open(self.datafile, 'r')
ind = 0
hash_find = re.compile('id="hash" value="([^"]+)"')
for line in df.readlines():
id = line.strip(' \n')
fp = PostCommand('http://vkontakte.ru/friends_ajax.php', req = 'act=request_form&fid=' + id)
fp.perform()
#print fp.res
for line1 in fp.res.split('\\n'):
if hash_find.search(line1.replace('\\', '')):
hash = hash_find.search(line1.replace('\\', '')).groups()[0]
break
try: hash
except:
print "Hash not found"
logging.debug("Hash for user %s not found!"%id)
continue
fp = PostCommand('http://vkontakte.ru/friends_ajax.php', req = 'act=accept_friend&fid=' + id + '&hash=' + hash +'&verbose=1&message=' + self.message)
fp.perform()
ind +=1
if ind >= self.limit: break
return ind


def extract_id(data):
result = ''
link = re.compile('<div class="info" id="row2(\d+)">')
for line in StringIO(data).readlines():
if link.search(line):
result += link.search(line).groups()[0] + '\n'
return result


def write_file(file, string):
file1 = open(file, 'w')
file1.write(string)
file1.close()

def add_to_file(file, data):
file1 = open(file, 'a')
file1.write(data)
file1.close()

def main(*args):
mail, password = sys.argv[1:]
#mail = "mymail@mail.ru"
#password = "mypass"
### For Windows change to your path
tmp_file = '/tmp/group_mems'
mail = mail.replace("@","%40")
mylogin = Vkontakte(mail, password).login()
#print "Your ID = ", mylogin
link = raw_input("Give link of group: ")
group_id = re.search('http://vkontakte.ru/club(\d+)', link).groups()[0]
gr = Group(group_id)
gr.find(datafile = tmp_file)

fr = Friend()
print "Added ", fr.add(datafile = tmp_file), " friends"
### Limit fo adding 30 friends, example:
#print "Added ", fr.add(datafile = '/tmp/group_mems', limit = 30), " friends"
### Add friends with message "Куку", example
#message_to_send = urllib.quote("Куку")
#print "Added ", fr.add(datafile = '/tmp/group_mems', message = message_to_send), " friends"

if __name__ == '__main__': main(sys.argv)

Или вот сылка http://code.google.com/p/socialbot/source/browse/trunk/trunk/kontakt.py
Прошу сильно не пинать, так в этом вопросе я еще большой новичок....

shell_c0de
25.02.2010, 17:58
Скачай интерпретатор питона и запускай =\

-tatarin-
25.02.2010, 18:37
Ну я это скачал уже был но потом он мне выдает ошибку вообщем вот сами смотрите:
ActivePython 2.6.4.10 (ActiveState Software Inc.) based on
Python 2.6.4 (r264:75706, Jan 22 2010, 16:41:54) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> #!/usr/bin/env python
... # -*- coding: utf-8 -*-
... # Created by Nuclear Worm
... #
... #
... # Vkontakte friends adder #
... # Version 0.1.a.1
... #
...
>>> import os, sys, time, re, logging, sqlite3, urllib, urllib2, cookielib
>>> try:
... from cStringIO import StringIO
... except ImportError:
... from StringIO import StringIO
... VERSION='0.1.a.1'
File "<stdin>", line 5
VERSION='0.1.a.1'
^
SyntaxError: invalid syntax
>>> COOKIEFILE = '/tmp/cookies1.lwp'
>>> LOG_FILENAME = '/tmp/dbg.log'
>>> logging.basicConfig(filename=LOG_FILENAME, filemode = 'w', level=logging.DEB
UG,)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\logging\__init__.py", line 1394, in basicConfig
hdlr = FileHandler(filename, mode)
File "C:\Python26\lib\logging\__init__.py", line 819, in __init__
StreamHandler.__init__(self, self._open())
File "C:\Python26\lib\logging\__init__.py", line 838, in _open
stream = open(self.baseFilename, self.mode)
IOError: [Errno 2] No such file or directory: 'C:\\tmp\\dbg.log'
>>>
>>> class PostCommand:
... def __init__(self, url, req = None):
... self.request = req
... self.headers = ''
... self.url = url
...
... def perform(self):
... cj = cookielib.LWPCookieJar()
... if os.path.isfile(COOKIEFILE): cj.load(COOKIEFILE)
... url_retr = urllib2.build_opener(urllib2.HTTPCookieProcessor(c j))
... self.res = url_retr.open(self.url, self.request).read()
... cj.save(COOKIEFILE)
... logging.debug("Got to PostCommand request = %s, url = %s"%(self.requ
est, self.url))
... #self.res = urllib.urlopen(self.url, self.request).read()
... logging.debug("Got result = %s"%self.res)
...
>>> class GetCommand:
... def __init__(self, url):
... self.headers = ''
... self.url = url
... def perform(self):
... cj = cookielib.LWPCookieJar()
... if os.path.isfile(COOKIEFILE): cj.load(COOKIEFILE)
... url_retr = urllib2.build_opener(urllib2.HTTPCookieProcessor(c j))
... self.res = url_retr.open(self.url).read()
... cj.save(COOKIEFILE)
... logging.debug("Got to GetCommand url = %s"%(self.url))
... #self.res = urllib.urlopen(self.url).read()
... logging.debug("Got result = %s"%self.res)
...
... class Vkontakte:
File "<stdin>", line 15
class Vkontakte:
^
SyntaxError: invalid syntax
>>> def __init__(self, mail, password):
File "<stdin>", line 1
def __init__(self, mail, password):
^
IndentationError: unexpected indent
>>> self.mail = mail
File "<stdin>", line 1
self.mail = mail
^
IndentationError: unexpected indent
>>> self.password = password
File "<stdin>", line 1
self.password = password
^
IndentationError: unexpected indent
>>>
... def login(self):
File "<stdin>", line 2
def login(self):
^
IndentationError: unexpected indent
>>> request = 'op=a_login_attempt&email=' + self.mail + '&pass=' + self.
password +'&expire=0'
File "<stdin>", line 1
request = 'op=a_login_attempt&email=' + self.mail + '&pass=' + self.password
+'&expire=0'
^
IndentationError: unexpected indent
>>> req = PostCommand('http://vkontakte.ru/login.php', request)
File "<stdin>", line 1
req = PostCommand('http://vkontakte.ru/login.php', request)
^
IndentationError: unexpected indent
>>> req.perform()
File "<stdin>", line 1
req.perform()
^
IndentationError: unexpected indent
>>> my_id = re.compile('good(\d+)')
File "<stdin>", line 1
my_id = re.compile('good(\d+)')
^
IndentationError: unexpected indent
>>> logging.debug("Reply from login:\n" + req.res)
File "<stdin>", line 1
logging.debug("Reply from login:\n" + req.res)
^
IndentationError: unexpected indent
>>> if "failed" in req.res: return "Error! Check your login/pass!"
File "<stdin>", line 1
if "failed" in req.res: return "Error! Check your login/pass!"
^
IndentationError: unexpected indent
>>> else:
File "<stdin>", line 1
else:
^
IndentationError: unexpected indent
>>> myid = my_id.search(req.res).groups()[0]
File "<stdin>", line 1
myid = my_id.search(req.res).groups()[0]
^
IndentationError: unexpected indent
>>> return myid
File "<stdin>", line 1
return myid
^
IndentationError: unexpected indent
>>>
>>> class Group:
... def __init__(self, group_id):
... self.group_id = group_id
...
... def find(self, datafile = None):
... if datafile: self.datafile = datafile
... else:
... print "No datafile to store your friends"
... sys.exit(1)
... gp = GetCommand('http://vkontakte.ru/search.php?group=' + self.group
_id)
... gp.perform()
... logging.debug("Reply from login:\n" + gp.res)
... sum = re.compile('<strong>.* (\d+) .*\.</strong>')
... all_those = sum.search(gp.res).groups()[0]
... logging.debug("Sum of all users in group:\n" + all_those)
... friends = extract_id(gp.res)
... add_to_file(self.datafile, friends)
... time.sleep(1)
... for i in range(1, int(all_those)/10 + 1):
... gp = GetCommand('http://vkontakte.ru/search.php?&group=' + self.
group_id + '&o=0&st=' + str(i*10))
... gp.perform()
... friends = extract_id(gp.res)
... add_to_file(self.datafile, friends)
... time.sleep(1)
... return sum
...
>>>
>>> class Friend:
... def __init__(self):
... pass
... def add(self, datafile = None, limit = None, message = None):
... if datafile: self.datafile = datafile
... else: pass
... if limit: self.limit = limit
... else: self.limit = 20000000
... if message: self.message = message
... else: self.message=''
... df = open(self.datafile, 'r')
... ind = 0
... hash_find = re.compile('id="hash" value="([^"]+)"')
... for line in df.readlines():
... id = line.strip(' \n')
... fp = PostCommand('http://vkontakte.ru/friends_ajax.php', req = '
act=request_form&fid=' + id)
... fp.perform()
... #print fp.res
... for line1 in fp.res.split('\\n'):
... if hash_find.search(line1.replace('\\', '')):
... hash = hash_find.search(line1.replace('\\', '')).groups
()[0]
... break
... try: hash
... except:
... print "Hash not found"
... logging.debug("Hash for user %s not found!"%id)
... continue
... fp = PostCommand('http://vkontakte.ru/friends_ajax.php', req =
'act=accept_friend&fid=' + id + '&hash=' + hash +'&verbose=1&message=' + self.me
ssage)
... fp.perform()
... ind +=1
... if ind >= self.limit: break
... return ind
...
...
>>> def extract_id(data):
... result = ''
... link = re.compile('<div class="info" id="row2(\d+)">')
... for line in StringIO(data).readlines():
... if link.search(line):
... result += link.search(line).groups()[0] + '\n'
... return result
...
>>>
>>> def write_file(file, string):
... file1 = open(file, 'w')
... file1.write(string)
... file1.close()
...
>>> def add_to_file(file, data):
... file1 = open(file, 'a')
... file1.write(data)
... file1.close()
...
>>> def main(*args):
... mail, password = sys.argv[1:]
... #mail = "mymail@mail.ru"
... #password = "mypass"
... ### For Windows change to your path
... tmp_file = '/tmp/group_mems'
... mail = mail.replace("@","%40")
... mylogin = Vkontakte(mail, password).login()
... #print "Your ID = ", mylogin
... link = raw_input("Give link of group: ")
... group_id = re.search('http://vkontakte.ru/club(\d+)', link).groups()[0]

... gr = Group(group_id)
... gr.find(datafile = tmp_file)
...
... fr = Friend()
... print "Added ", fr.add(datafile = tmp_file), " friends"
... ### Limit fo adding 30 friends, example:
... #print "Added ", fr.add(datafile = '/tmp/group_mems', limit = 30), " f
riends"
... ### Add friends with message "Куку", example
... #message_to_send = urllib.quote("Куку")
... #print "Added ", fr.add(datafile = '/tmp/group_mems', message = message
_to_send), " friends"
...
>>> if __name__ == '__main__': main(sys.argv) ( нажал тут я enter)
...( появились эти 3 точки, я ще раз нажал enter и вот далее ошибка)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in main
ValueError: need more than 0 values to unpack
>>>

undef
26.02.2010, 02:31
Извращенец. Зачем копипастить файл интерпретатору? Установил свой ActiveState Python, cmd.exe -> DISK: -> cd \path\to\your\dir\ -> file.py
После установки его в систему, все .py файлы будут запускаться через него.

Supermanoff
26.02.2010, 16:52
1. В предыдущем посте написано, что тебе надо сделать, чтобы запустить скрипт!
2. Скрипт этот уже давно не работает!

-tatarin-
26.02.2010, 20:11
Спсибо большое за помощь всем, действительно скрипт не рабочий((((((((.....Supermanoff, не знаешь существует ли новый скрипт? Буду очень рад если поможешь...........