Code Docta (Nick C.) 638 Posted May 11, 2015 Report Share Posted May 11, 2015 Hello U-Py-Botters!! This little bot script will post a status on *Tw*i*t*t*er* for ya and it is made with Python too So this will introduce you to a little thing called Session() objects which will allow you to login and post a status and much more. The Requests module is thread safe and is very robust and will handle cookies in anyway imaginable. Take a looksy here for Requests Cookies This requires one Plugin and Python to be installed. FREE python plugin python 34 installation videos (the funnier one) NEW install Python on Windows for UBot This will be one of ??? I make to show you a bit about Python and how it works in Ubot. Here is part of the script... comment("PLEASE MAKE SURE PATH IS CORRECT TO YOUR PYTHON EXE IN FUNCTIONS TAB THIS IS THE BASIC VERSION MORE ADVANCED WILL SOON FOLLOW") ui text box("Usename/Email:", #UI_TB_username) ui text box("Password:", #UI_TB_password) ui text box("Tweet your status!", #UI_YB_tweet) ui button("Tweet meh!!!") { comment("There is an import that I left in from contextlib import closing it is for closing the HTTP connections instes of using resp.close() or ses.close() in this case. I will show this in the next tut. So while in this I did not add any as the plugin seams to lose all data. IN PRODUCTION I WOULD USE THEM ALONG WITH THE del KEYWORD TO CLEAR VARIABLES AND ITERABLES ig list, dict, and tuples") set(#tweet resp, $plugin function("ExecutePython.dll", "Execute From Code", "{$Py imports("import requests, regex from contextlib import closing from pprint import pprint from lxml import html")} ses = requests.Session() CONNTO = 15 #this is a connection timeout URL = \'https://twitter.com/\' UA = \'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0\' REFER = \'\' HEADS = {$curly OPEN()}\'User-Agent\': UA, \'Referer\': REFER{$curly CLOSE()} UN = \'{#UI_TB_username}\' PW = \'{#UI_TB_password}\' try: resp = ses.get(URL, headers=HEADS, timeout=CONNTO) #print(resp.status_code) #print(resp.cookies) #cookies set #print(\'\') #print(resp.headers[\'Cookie\']) #response headers #print(\'\') #print(resp.request.headers) #headers you sent except Exception as respError: print(\'Something happened with first get response!!\') print(\'\') print(respError) rText = resp.text rXpath = html.fromstring(rText) authKey = rXpath.xpath(\"//input[@name=\'authenticity_token\']//@value\")[0] pURL = \'https://twitter.com/sessions\' REFER = URL HEADS = {$curly OPEN()}\'User-Agent\': UA, \'Referer\': REFER{$curly CLOSE()} PARAMS = {$curly OPEN()} \'session[username_or_email]\': UN, \'session[password]\': PW, \'remember_me\': 1, \'return_to_ssl\': \'true\', \'scribe_log=&redirect_after_login\': \'/\', \'authenticity_token\': authKey {$curly CLOSE()} try: postResp = ses.post(pURL, headers=HEADS, data=PARAMS, timeout=CONNTO) #print(postResp.status_code) #print(postResp.cookies) #cookies set #print(\'\') #print(postResp.headers) #response headers #print(\'\') #print(postResp.request.headers) #headers you sent except Exception as postRespError: print(\'Something happened with first Post response!!\') print(\'\') print(postRespError) TWEET = \'{#UI_YB_tweet} \' REFER = \'https://twitter.com\' HEADS = {$curly OPEN()}\'User-Agent\': UA, \'Referer\': REFER{$curly CLOSE()} tPARAMS = {$curly OPEN()}\'authenticity_token\': authKey, \'place_id\': \'\', \'status\': TWEET, \'tagged_users\': \'\'{$curly CLOSE()} tURL = \'https://twitter.com/i/tweet/create\' try: tweetResp = ses.post(tURL, headers=HEADS, data=tPARAMS, timeout=CONNTO) print(tweetResp.status_code) #print(tweetResp.cookies) #cookies sent #print(\'\') #print(tweetResp.text) #print(tweetResp.headers) #response headers #print(\'\') #print(tweetResp.request.headers) #headers you sent except Exception as tweetRespError: print(\'Something happened with first tweet response!!\') print(\'\') print(tweetRespError) ", $Anaconda file path()), "Global") comment("There are # in front of some print statements they are to comment those lines out. If you remonve the # it will run that line. This is one way to do commenting. The other is triple quotes. I just left them in so you can play. It is best to play in an IDE like the Ipython Notebook it is also known as Jupyter") } ui stat monitor("Tweet Response:", #tweet resp) divider stop script comment("One might make a recipe like this... To keep more organized. You can put other functions as well like anther python script") load html($plugin function("ExecutePython.dll", "Execute From Code", "{$Py imports("import requests, regex from contextlib import closing from pprint import pprint from lxml import html")} ses = requests.Session() {$Py Headers("CONNTO = 15 #this is a connection timeout URL = \'https://twitter.com/\' UA = \'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0\' REFER = \'\' HEADS = {$curly OPEN()}\'User-Agent\': UA, \'Referer\': REFER{$curly CLOSE()}")} UN = \'{#UI_TB_username}\' PW = \'{#UI_TB_password}\' try: resp = ses.get(URL, headers=HEADS, timeout=CONNTO) #print(resp.status_code) #print(resp.cookies) #cookies set #print(\'\') #print(resp.headers[\'Cookie\']) #response headers #print(\'\') #print(resp.request.headers) #headers you sent except Exception as respError: print(\'Something happened with first get response!!\') print(\'\') print(respError) rText = resp.text rXpath = html.fromstring(rText) authKey = rXpath.xpath(\"//input[@name=\'authenticity_token\']//@value\")[0] {$Py Headers("pURL = \'https://twitter.com/sessions\' REFER = URL HEADS = {$curly OPEN()}\'User-Agent\': UA, \'Referer\': REFER{$curly CLOSE()}")} {$Py Parameters("PARAMS = {$curly OPEN()} \'session[username_or_email]\': UN, \'session[password]\': PW, \'remember_me\': 1, \'return_to_ssl\': \'true\', \'scribe_log=&redirect_after_login\': \'/\', \'authenticity_token\': authKey {$curly CLOSE()}")} try: postResp = ses.post(pURL, headers=HEADS, data=PARAMS, timeout=CONNTO) #print(postResp.status_code) #print(postResp.cookies) #cookies set #print(\'\') #print(postResp.headers) #response headers #print(\'\') #print(postResp.request.headers) #headers you sent except Exception as postRespError: print(\'Something happened with first Post response!!\') print(\'\') print(postRespError) TWEET = \'{#UI_YB_tweet} \' {$Py Headers("REFER = \'https://twitter.com\' HEADS = {$curly OPEN()}\'User-Agent\': UA, \'Referer\': REFER{$curly CLOSE()}")} {$Py Parameters("tPARAMS = {$curly OPEN()}\'authenticity_token\': authKey, \'place_id\': \'\', \'status\': TWEET, \'tagged_users\': \'\'{$curly CLOSE()}")} tURL = \'https://twitter.com/i/tweet/create\' try: tweetResp = ses.post(tURL, headers=HEADS, data=tPARAMS, timeout=CONNTO) print(tweetResp.status_code) #print(tweetResp.cookies) #cookies sent #print(\'\') #print(tweetResp.text) #print(tweetResp.headers) #response headers #print(\'\') #print(tweetResp.request.headers) #headers you sent except Exception as tweetRespError: print(\'Something happened with first tweet response!!\') print(\'\') print(tweetRespError) ", $Anaconda file path())) comment("You will notice if you tweet the same tweet will give 403 error as you can not tweet the same tweet so make sure to change it for it to work. Please follow me @CodeDocta Hope this made sense.") For this script to work you will need to download the attatched file. As you can see there are many comments and some extra lines in there for debuging purposes.Please be aware this is very basic and more adbanced bots are sure to follow...So follow me on twitter@CodeDocta and stay up to date with my shinanigains!! Enjoy, CDexample--Python-HTTP-twitter.ubot 2 Quote Link to post Share on other sites
Brutal 164 Posted July 16, 2015 Report Share Posted July 16, 2015 I look forward to seeing your process - I had assumed that py was able to run out-of-the-box with ubot 5, but it appears I was wrong. Quote Link to post Share on other sites
mithcd 4 Posted July 19, 2015 Report Share Posted July 19, 2015 Thanks a lot for giving this out for free. Looking forward to try this one out. Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted July 30, 2015 Author Report Share Posted July 30, 2015 I look forward to seeing your process - I had assumed that py was able to run out-of-the-box with ubot 5, but it appears I was wrong. I have something special coming soon. It does kinda sorta it a ubot way.But this something special is worth having it in ubot just for my surprise alone. @mithcd Hope you like it. CD Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted June 9, 2017 Author Report Share Posted June 9, 2017 updated op NEW install Python on Windows for UBot 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.