コード例 #1
0
ファイル: shorten_url.py プロジェクト: beshrkayali/twython
import twython as twython

# Shortening URLs requires no authentication, huzzah
twitter = twython.setup()
shortURL = twitter.shortenURL("http://www.webs.com/")

print shortURL
コード例 #2
0
ファイル: poll.py プロジェクト: simbha/proxytweet
 def __init__(self):
   self.twitter = twython.setup()
コード例 #3
0
    def __init__(self,
                 complete_name=None,
                 screen_name=None,
                 passwd=None,
                 create=True):
        '''
        Constructor
        '''

        self.debug = True

        if not screen_name or not complete_name or not passwd:
            raise Exception(
                'no Twitter screen name or no complete name or no passwd specified specified!'
            )

        self.complete_name = complete_name
        self.screen_name = screen_name
        self.passwd = passwd
        self.email = self.get_tenminutemail(
        )  #'*****@*****.**' # '*****@*****.**'  #screen_name + '*****@*****.**'
        print self.email

        if not create:
            self.__settings = twython.setup(
                username=self.screen_name,
                password=self.passwd,
            )
            return

        #self.__br = Browser()
        #self.__br.set_proxies(proxies_per_proto)
        #self.__br.set_debug_http(True)

        # no handling of robots.txt to avoid extra GETs.
        #self.__br.set_handle_robots(False)

        try:
            # sign into Twitter
            resp = self.__br.open("https://twitter.com/signup")

            cont = resp.read()
            recaptcha_url = re.findall(
                'https:\/\/api-secure.recaptcha.net\/challenge\?k=[a-zA-Z0-9]+',
                cont)[0]

            recaptcha_cont = urllib2.urlopen(recaptcha_url).read()
            print recaptcha_cont
            recaptcha_challenge = re.findall(
                'challenge : \'[a-zA-Z0-9_-]+\'',
                recaptcha_cont)[0][len('challenge : \''):-len('\'')]

            print 'opening https://api-secure.recaptcha.net/image?c=%s' % recaptcha_challenge
            recaptcha_jpg = urllib2.urlopen(
                'https://api-secure.recaptcha.net/image?c=%s' %
                recaptcha_challenge).read()

            jpg_filename = '/tmp/%s.jpg' % time.ctime().replace(' ', '_')
            jpg = open(jpg_filename, 'w')
            jpg.write(recaptcha_jpg)
            jpg.close()
            os.system('eog %s' % jpg_filename)

            recaptcha_response = raw_input("Enter recaptcha words: ")

            url = 'https://twitter.com/account/create'
            values = {
                'user[name]': complete_name,
                'user[screen_name]': screen_name,
                'user[user_password]': passwd,
                'user[email]': self.email,
                'recaptcha_response_field': recaptcha_response,
                'recaptcha_challenge_field': recaptcha_challenge
            }

            data = urllib.urlencode(values)
            req = urllib2.Request(url, data)

            self.__br.select_form(nr=0)
            resp = urllib2.urlopen(req)

            time.sleep(2.0)

            self.__good = True

            #json_string = self.__br.open(self.user_url % self.screen_name).read()
            #user_profile = json.loads(json_string)
            #self.user_details = user_profile
            #self.num_id = user_profile['id']

        except Exception, e:
            print str(e)
            print 'EXCEPTION on TwitterControlledNode, possibly bad user/password or https login don\' work behind a proxy.'
            self.__good = False
コード例 #4
0
	def update(self):
		self.date_updated = datetime.datetime.now()
		twitter = setup()
		self.profile = twitter.showUser(screen_name=unicode(self.user.username))
コード例 #5
0
class TwitterControlledNode(TwitterNode):
    def get_tenminutemail(self):

        mail_url = 'http://10minutemail.com/10MinuteMail/'
        self.mail_url = mail_url

        self.__br = Browser()
        #self.__br.set_proxies(proxies_per_proto)
        self.__br.set_debug_http(self.debug)

        # no handling of robots.txt to avoid extra GETs.
        self.__br.set_handle_robots(False)

        resp = self.__br.open(mail_url)
        cont = resp.read()

        mail = re.findall('[a-z0-9]+@bofthew\.com', cont)[0]
        return mail

    def confirm_tenminutemail(self, mail_number=0):

        confirm_mail_url = 'http://10minutemail.com/10MinuteMail/index.html?dataModelSelection=message%3Aemails%5B' + str(
            mail_number) + '%5D&actionMethod=index.xhtml%3AmailQueue.select'

        print 'Waiting 60 seconds to try confirm e-mail...'
        time.sleep(60.0)

        attempts = 19
        while attempts > 0:
            self.__br.open(self.mail_url)
            time.sleep(1.0)
            print 'waiting 0 ...'
            resp = self.__br.open(confirm_mail_url)
            cont = resp.read()
            print 'waiting 1...'
            time.sleep(1.0)
            #print cont
            print 'waiting 2...'
            time.sleep(1.0)
            try:
                twitter_confirm_mail_url = re.findall(
                    'http:\/\/twitter\.com\/account\/confirm_email\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+',
                    cont)[0]
                resp = self.__br.open(twitter_confirm_mail_url)
                print 'waiting 3 (good arrival of confimation mail???)...'
                time.sleep(1.0)
                # sign in to finish!
                cont = resp.read()
                self.__br.select_form(nr=1)
                self.__br['session[username_or_email]'] = self.email
                self.__br['session[password]'] = self.passwd
                resp = self.__br.submit()
                print 'waiting 4 (good confimation mail arrival, signing in to twitter to complete confirmation???)...'
                time.sleep(1.0)
                break
            except:
                attempts -= 1
                print 'Waiting 60 seconds to retry confirm e-mail (attempt left %d) ...' % attempts
                time.sleep(60.0)

                if attempts == 12:
                    resp = self.__br.open(self.mail_url)
                    cont = resp.read()
                    extend_time_url = re.findall(
                        'http:\/\/10minutemail\.com\/10MinuteMail\/index\.html\?cid=[0-9]+&actionMethod=index\.xhtml%3AmailQueue\.resetSessionLife',
                        cont)
                    self.__br.open(extend_time_url)
                    print 'waiting (extending 10minutemail time)...'
                    time.sleep(5.0)

        if attempts == 0:
            raise Exception('Error: unable to confirm e-mail for Twitter!')

    def __init__(self,
                 complete_name=None,
                 screen_name=None,
                 passwd=None,
                 create=True):
        '''
        Constructor
        '''

        self.debug = True

        if not screen_name or not complete_name or not passwd:
            raise Exception(
                'no Twitter screen name or no complete name or no passwd specified specified!'
            )

        self.complete_name = complete_name
        self.screen_name = screen_name
        self.passwd = passwd
        self.email = self.get_tenminutemail(
        )  #'*****@*****.**' # '*****@*****.**'  #screen_name + '*****@*****.**'
        print self.email

        if not create:
            self.__settings = twython.setup(
                username=self.screen_name,
                password=self.passwd,
            )
            return

        #self.__br = Browser()
        #self.__br.set_proxies(proxies_per_proto)
        #self.__br.set_debug_http(True)

        # no handling of robots.txt to avoid extra GETs.
        #self.__br.set_handle_robots(False)

        try:
            # sign into Twitter
            resp = self.__br.open("https://twitter.com/signup")

            cont = resp.read()
            recaptcha_url = re.findall(
                'https:\/\/api-secure.recaptcha.net\/challenge\?k=[a-zA-Z0-9]+',
                cont)[0]

            recaptcha_cont = urllib2.urlopen(recaptcha_url).read()
            print recaptcha_cont
            recaptcha_challenge = re.findall(
                'challenge : \'[a-zA-Z0-9_-]+\'',
                recaptcha_cont)[0][len('challenge : \''):-len('\'')]

            print 'opening https://api-secure.recaptcha.net/image?c=%s' % recaptcha_challenge
            recaptcha_jpg = urllib2.urlopen(
                'https://api-secure.recaptcha.net/image?c=%s' %
                recaptcha_challenge).read()

            jpg_filename = '/tmp/%s.jpg' % time.ctime().replace(' ', '_')
            jpg = open(jpg_filename, 'w')
            jpg.write(recaptcha_jpg)
            jpg.close()
            os.system('eog %s' % jpg_filename)

            recaptcha_response = raw_input("Enter recaptcha words: ")

            url = 'https://twitter.com/account/create'
            values = {
                'user[name]': complete_name,
                'user[screen_name]': screen_name,
                'user[user_password]': passwd,
                'user[email]': self.email,
                'recaptcha_response_field': recaptcha_response,
                'recaptcha_challenge_field': recaptcha_challenge
            }

            data = urllib.urlencode(values)
            req = urllib2.Request(url, data)

            self.__br.select_form(nr=0)
            resp = urllib2.urlopen(req)

            time.sleep(2.0)

            self.__good = True

            #json_string = self.__br.open(self.user_url % self.screen_name).read()
            #user_profile = json.loads(json_string)
            #self.user_details = user_profile
            #self.num_id = user_profile['id']

        except Exception, e:
            print str(e)
            print 'EXCEPTION on TwitterControlledNode, possibly bad user/password or https login don\' work behind a proxy.'
            self.__good = False

        if self.__good:

            self.confirm_tenminutemail()

            self.__settings = twython.setup(
                username=self.screen_name,
                password=self.passwd,
            )