# Simple Twitter Bot with oAuth
# No callback's and other shit required
import os
import sys
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template, util
from google.appengine.api import urlfetch
import oauth
# First you need to create an app here
# http://twitter.com/oauth or http://dev.twitter.com/apps/
# and get the codes below
TWITTER_CONSUMER_KEY = 'CODE+GOES+HERE'
TWITTER_CONSUMER_SECRET = 'CODE+GOES+HERE'
# The next codes are found http://dev.twitter.com/apps/
# right menu, after you clicked on the app
TWITTER_ACCESS_TOKEN = 'CODE+GOES+HERE'
TWITTER_ACCESS_TOKEN_SECRET = 'CODE+GOES+HERE'
class Tweet(webapp.RequestHandler):
def status(self, url):
try:
result = urlfetch.fetch(url, method = urlfetch.HEAD)
if result.status_code == 200:
return "Website OK"
else:
return ('Site error code: ' + str(result.status_code))
except urlfetch.DownloadError:
return "Website DOWN, for good. (getadress error)"
def get(self):
status = self.status("http://necenzurat.com") #your website here
#print "content-type: text/plain"
print status
try:
client = oauth.TwitterClient(TWITTER_CONSUMER_KEY,
TWITTER_CONSUMER_SECRET,
None
)
webstatus = {
"status": status,
"lat": 44.42765100,
"long":26.103172
}
#comment the request below for debugging
client.make_request('http://twitter.com/statuses/update.json',
token=TWITTER_ACCESS_TOKEN,
secret=TWITTER_ACCESS_TOKEN_SECRET,
additional_params=webstatus,
protected=True,
method='POST'
)
except:
self.response.out.write("Exception: <pre>")
self.response.out.write(sys.exc_info());
self.response.out.write("</pre>");
def main():
application = webapp.WSGIApplication([('/check', Tweet)])
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
Ok so Twitter just fucked up Basic Auth for Twitter API since 1 september 2010 (well my bot’s stop working on 2 sept)
August 31, 2010 Basic Auth has been deprecated. All applications must now use OAuth.- Twitter
So this is a bit annoying for some reasons.
1. I hate using libs for a 20 min project.
2. I hate to create an app just to make a simple demo on a twitter account.
3. other reasons goes here.
Well if you are an ex Basic Auth fan you have to go to the new OAuth (shit) method well i am not here to tank so here is how to modify your cod from old style to new.
So this is how my old code used to be:
$url = "twitter_user:twitter_password@twitter.com/statuses/update.xml";
$curl = curl_init();
$post = "&status=$message"; //you can add here alot of things like &lat=&long
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_exec ($curl);
curl_close ($curl);
See how simple it was?
But now if you just need to make a simple fucking update from php you need to:
1. Go to dev.twitter.com/apps and register your app, if you need a simple app you don’t need to enter callback url and just select the application is Desktop like in the example below:
2. Now click on the new created application and fill in the gaps below:
$consumer_key = "gap you need to fill";
$consumer_secret = "gap you need to fill";
/* see point 3 for this part */
$access_key = "gap you need to fill";
$access_secret = "gap you need to fill";
3. The access key can be found in the menu of your newly created app:
4. Go to the web and download this twitter library. For this simple example you just need 2 files that are in the twitteroauth/ folder
so let’s make an example:
$consumer_key = "gap you need to fill";
$consumer_secret = "gap you need to fill";
/* see point 3 for this part */
$access_key = "gap you need to fill";
$access_secret = "gap you need to fill";
require_once('twitteroauth/twitteroauth.php');
$twitter = new TwitterOAuth ($consumer_key ,$consumer_secret , $access_key , $access_secret );
$twitter->post('statuses/update', array('status' => "Hello World from OAuth! Goodbye Basic Auth",
'lat' => "44.42765100",
'long' => "26.103172",
));
Ze end.
If you have problems lemme know in the comments.
PS: i say bot because i used this shit for a Twitter bot
Noun.
A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can’t stand one bit of competition.
The Code Fairy is a fictional spirit said to eat semicolons and curly braces from computer source code.
It is well known that the Windows code fairy has the largest wings but cannot fly. The Apple code fairy has the most beautiful wings but they are so small that everyone believes they don’t exist. The Linux code fairy looks different depending on who kissed it last. The UNIX code fairy looks like grumpy and old. The SCO-Linux code fairy looks like a lawyer and pursues anyone who kisses the Linux code fairy.
The Code Fairy is an example of folklore mythology which non-programmers know is fiction, but which is sometimes presented by computer programmers as fact, as a way of explaning how a computer program stops working after compiling it, without altering the source code.
After half an hour of looking on the damm documentation on Google Analytics Async code… screw it… did’t find some useful info about how tot track outgoing links so i stumble (not like stumbleupon) on this piece of code:
onload = function(){
var tracker = 'UA-XXXXXXX-X'; // change this
var domain = 'yourwebsite.tld'; // change this
var code = "var _gaq = _gaq||[];_gaq.push(['_setAccount', '" + tracker + "'],['_setDomainName', '" + domain + "'],['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);})();";
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.innerHTML = code;
document.body.insertBefore(newScript, document.body.firstChild);
var allA = document.getElementsByTagName('a');
var domainRegex = new RegExp ( "http:\/\/" + domain.replace(".","\\.") , "i");
if ( typeof(allA) != "undefined") {
for (i = 0; i < allA.length; i++) {
var newAttr = null;
var newAttrText = null;
var oldAttr = null;
var href = allA[i].href;
if (!href.match(domainRegex)) {
newAttrText = href.replace(/http:\/\//i,"");
if (newAttrText.length > 0) {
if (allA[i].getAttribute("onclick") != null) {
oldAttr = allA[i].getAttribute("onclick") + ";";
}
newAttr = document.createAttribute("onclick");
if (oldAttr == null) newAttr.nodeValue = "_gaq.push(['_trackPageview', 'out/" + newAttrText + "'])";
else newAttr.nodeValue = oldAttr + "_gaq.push(['_trackPageview', 'out/" + newAttrText + "'])";
allA[i].setAttributeNode(newAttr);
}
}
}
}
}
basically it will dynamically add some code to all of your link in HTML
So the thing is i am tired to log into shell, to wget the latest wordpress zip, unzip it and then login via SFTP and move some folders… to much hassle.
So after 20 minutes of work and trying to figure why the mv command is not moving my folders and just the files i did it :’)
The script just get’s the latest version of WordPress and unzip it in the folder that you put the script: