Archive for the ‘Internet’ category

My little hack on Pidgin

February 16, 2012

I hope you have had the good luck of using one of the best IM-client available named pidgin. You can find a whole lot of posts around telling about why it’s good and all so I am skipping it.

Now, this post is not aimed at dragging you to use pidgin. It’s actually about one good thing I stumbled upon when using it.

Usually when I am chatting with people, I find myself using terms they sometimes don’t know. So, the next usual thing to be done is to ask them to go and google it. (duh!) Now, wouldn’t it be better to just give them a link directly.!

I was thinking of making a plugin myself for this which would keep an eye on what I write and replace it with google links as and when required. But it required time.!

Luckily, I found another plugin by default in Pidgin which does the job for me. I am using Pidgin 2.7.9

  • Go to Tools->Plugins
  • Find a plugin named Text Replacement 2.7.9
  • Enable it by clicking on the little check-box by it’s side
  • Now click on the Configure Plugin just below the whole list of plugins.
  • Fill: You type -> !google
  • Fill: You type -> http://www.google.com/search?q=
  • Un-check¬† (remove the tick) Only replace whole words
  • Check (tick it) exact case match
  • Click on Add

Now you have got a kind of Bot which would create links for you.. ūüôā

How to use it:

  • When chatting let your query be “techmyway”
  • Type in !googletechmyway
  • Press enter (and the link gets inserted) voila! ūüôā

OR (this is what happens in my case)

  • whenever you write “!google” it is automatically replaced with the link

Now here is the catch: the queries can only be single-worded. The space is not recognized in urls. You would have to use %20 instead of space character. Also, remember not to try to replace every space with %20, your whole chat can get messed up.!

Share the info if you like.

Advertisements

The new dropbox API

October 22, 2011

Just going through the feeds I found out that Dropbox had given out new APIs. Luckily, they had better support for python this time.

Going along, I have written a script (or an introduction you can say) to these APIs in Python.

I have tried to document the code as much as possible.

do remember to install oauth, setuptools, simplejson as these are not included by default in Python 2.7 installation


## author: Ayush Goel
## Python 2.7 used
## get the Dropbox new API from https://www.dropbox.com/developers/
## mail: ayushgoel111@gmail.com

## do remember to install oauth, setuptools, simplejson
## not included by default in Python 2.7 installation
## http://pypi.python.org/pypi/setuptools
## http://pypi.python.org/pypi/oauth/1.0.1
## http://pypi.python.org/pypi/simplejson/

# Include the Dropbox SDK libraries
from dropbox import client, rest, session

# Get your app key and secret from the Dropbox developer website
APP_KEY =    'INSERT_APP_KEY_HERE'
APP_SECRET =  'INSERT_SECRET_HERE'

# ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app
ACCESS_TYPE = "app_folder" #'INSERT_ACCESS_TYPE_HERE'
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)

request_token = sess.obtain_request_token()

while True:
  url = sess.build_authorize_url(request_token)
  print "url:", url
  import webbrowser
  webbrowser.open_new_tab(url)
  print "You have been redirected to the authorization page."
  print "Please do the authorization within 5 minutes else the URL would expire."
  print "Press ENTER here once you are done. To create the url again, enter any character"
  #print "Please visit this website and press the 'Allow' button, then hit 'Enter' here."
  s=raw_input()
  if s=='':
    break

# This will fail if the user didn't visit the above URL and hit 'Allow'
access_token = sess.obtain_access_token(request_token)

client = client.DropboxClient(sess)
print "linked account:", client.account_info()

## The client object is what is required for the whole
## app buildup by anyone

## anyways, lets have a look at some things of interest of
## all those tokens we just saw

## the url we produced above
print  url
#'https://www.dropbox.com/1/oauth/authorize?oauth_token=n8yyjthf92hv1g5'

print sess.API_CONTENT_HOST
# 'api-content.dropbox.com'
print sess.API_HOST
# 'api.dropbox.com'
print sess.API_VERSION
# 1
print  sess.WEB_HOST
# 'www.dropbox.com'
print  sess.is_linked()
# True
print  sess.locale
# nothing None
print  sess.root
# 'sandbox'
print  sess.signature_method.get_name()
# 'PLAINTEXT'

## Very important to NOTICE: every token we generated
## has two unique identifiers (key, secret)

print  request_token.key
# 'n8yyjthdgff92hvasafd1g5'
print  request_token.secret
# 'qu1dfozfgafeg1hmwrijwum'
print  request_token.verifier
# None
print  access_token.key
# 'd2rdsfjjfgzgd8hwc3j9kiiof'
print  access_token.secret
# 'wfsdfjwglhho0odek2jqby44'

print  access_token.callback_confirmed
# None
print  access_token.get_callback_url()
# None

## file_create_folder() creates a folder in the app folder given to you.
## The folder name is passed as an argument
## a dict is returned giving details of the folder
## errors are raised otherwie (see the documentation)

print client.file_create_folder("folder1")
##        {
##        u'size': u'0 bytes',
##        u'rev': u'104721f34',
##        u'thumb_exists': False,
##        u'bytes': 0,
##        u'modified': u'Fri, 21 Oct 2011 19:48:25 +0000',
##        u'path': u'/folder1',
##        u'is_dir': True,             # memory management
##        u'icon': u'folder',
##        u'root': u'app_folder',      # authotization
##        u'revision': 1
##        }

## client.put_file("C:\Users\Ayush\Desktop\dropify.txt","folder1/")
##
##Traceback (most recent call last):
##  File "<pyshell#31>", line 1, in <module>
##    client.put_file("C:\Users\Ayush\Desktop\dropify.txt","folder1/")
##  File "C:\Users\Ayush\Applications\python_pkg\dropbox-python-sdk-1.2\dropbox-1.2\dropbox\client.py", line 147, in put_file
##    return RESTClient.PUT(url, file_obj, headers)
##  File "C:\Users\Ayush\Applications\python_pkg\dropbox-python-sdk-1.2\dropbox-1.2\dropbox\rest.py", line 142, in PUT
##    return cls.request("PUT", url, body=body, headers=headers, raw_response=raw_response)
##  File "C:\Users\Ayush\Applications\python_pkg\dropbox-python-sdk-1.2\dropbox-1.2\dropbox\rest.py", line 109, in request
##    raise ErrorResponse(r)
##ErrorResponse: [400] {u'path': u"Path 'C:\\Users\\Ayush\\Desktop\\dropify.txt' can't contain \\"}

## correct way of uploading a file
f=open("C:\Users\Ayush\Desktop\dropify.txt")
print client.put_file("folder1/dropify.txt",f)

##        {
##        u'size': u'34 bytes',
##        u'rev': u'204721f34',
##        u'humb_exists': False,
##        u'bytes': 34,
##        u'modified': u'Fri, 21 Oct 2011 19:57:39 +0000',
##        u'path': u'/folder1 (1)',
##        u'is_dir': False,
##        u'icon': u'page_white',
##        u'root': u'app_folder',
##        u'mime_type': u'application/octet-stream',
##        u'revision': 2
##        }

##read a file from dropbox
## we are actually reading the same file we just
## uploaded. It's a text document
a=client.get_file("folder1/dropify.txt")

print a.fileno()
# 588

## get headers of the file we are reading
## a list of tuples is returned
## difference between tuples and lists will be covered later

print a.getheaders()
##        [
##        ('content-length', '34'),
##        ('accept-ranges', 'bytes'),
##        ('server', 'dbws'),
##        ('connection', 'keep-alive'),
##        ('etag', '2n'),
##        ('pragma', 'public'),
##        ('cache-control', 'max-age=0'),
##        ('date', 'Fri, 21 Oct 2011 19:59:28 GMT'),
##        ('content-type', 'text/plain; charset=ascii')
##        ]

print a.read()
## the contents
## please don't do this on your "big files"
## may slow down or clog your app as memory requirements would go very high

## some additional data about the file
print a.reason
# 'OK'
print a.status
# 200
print  a.strict
# 0
print  a.version
# 11
print  a.chunk_left
# 'UNKNOWN'
print  a.chunked
# 0
print  a.begin()
# None
print  a.read()
# ''

## another list of headers
s=a.getheaders()

# I am actually printing the headers beautifully ūüôā
for i in s:
print "%15s%s%20s"%(i[0]," : ", i[1])

## content-length :                   34
##  accept-ranges :                bytes
##         server :                 dbws
##     connection :           keep-alive
##           etag :                   2n
##         pragma :               public
##  cache-control :            max-age=0
##           date : Fri, 21 Oct 2011 19:59:28 GMT
##   content-type : text/plain; charset=ascii

print  client.metadata('/')
##{
##        u'hash': u'00d3e63a8e91467dddaf18d04b206e57',
##        u'thumb_exists': False,
##        u'bytes': 0,
##        u'path': u'/',
##        u'is_dir': True,
##        u'icon': u'folder',
##        u'root': u'app_folder', u
##        'contents': [
##                {
##                        u'size': u'0 bytes',
##                        u'rev': u'104721f34',
##                        u'thumb_exists': False,
##                        u'bytes': 0,
##                        u'modified': u'Fri, 21 Oct 2011 19:48:25 +0000',
##                        u'path': u'/folder1',
##                        u'is_dir': True,
##                        u'icon': u'folder',
##                        u'root': u'dropbox',
##                        u'revision': 1
##                },
##                {
##                        u'size': u'34 bytes',
##                        u'rev': u'204721f34',
##                        u'thumb_exists': False,
##                        u'bytes': 34,
##                        u'modified': u'Fri, 21 Oct 2011 19:57:39 +0000',
##                        u'path': u'/folder1',
##                        u'is_dir': False,
##                        u'icon': u'page_white',
##                        u'root': u'dropbox',
##                        u'mime_type': u'application/octet-stream',
##                        u'revision': 2
##                }
##        ],
##        u'size': u'0 bytes'
##}

And yes, I have tested this on my machine, so I am sure it is working..

So, put your coding caps on and go get your own keys from dropbox.

And yes, don’t worry about the .key and .secret , they are scrambled and tempered with.. ūüėČ

Retrieving files from URLs

October 20, 2011

This script was writeen by me way long back. I documented it a little so that it’s easy to understand what it’s trying to do.

## python 3.x compliant
## author: Ayush Goel

import urllib.request as ur

file_url=input('Enter the file URL you want to be downloaded: ')
file_name=input('Enter the path where you want the file to be saved(/enter): ')

if file_name=='':
## if no location provided, we get ourselves a default one

## change the location of download as suited for you
## this one worked on my Win7 machine
file_name='C:\\Users\\Ayush\\Downloads'+file_url.split('/')[-1]

try:
## try to retrieve the file using the URL
ur.urlretrieve(file_url,filename=file_name)

except ur.URLError:
## urls like : "edoc.ub.uni-muenchen.de/7505/1/Fischer_Johannes.pdf"
## headers like http:// https:// are missing
print ("The URL is parsed to be incorrect.. please provide with the complete url, including the protocol name (http,https..)")

except IOError:
## the url given ain't to a file.
## It might be a forwarding URL, we would need the actual file url
print("We are facing issues with the url you provided")

I have included some error issues. If you find any, comment here or PM me.

RSS feeds for nokia 2690

June 20, 2011

I am a proud user of Nokia 2690, an entry level phone. Though it is “said to be” a very low grade phone, but I find it to be amazing and full of features.

Seriously, a 2500 INR wit features as great as a good bluetooth, edge connection, opera browser, memory card compatibility and a 3.5mm jack is difficult to find.

Recently I was finding an application to read RSS feeds on it. I though found an application, but found another ewasy way to do it. The inbuilt Opera browser is capable of reading the feeds!! Just added the links to follow and it was done..

Give it a try.. ūüôā

Document corrupter

April 9, 2011

Often we are in a hurry to complete our work and still are unable to complete it. This is the time when we pray to god to just extend the day or do some miracle like that. Not anymore. Here I found a tool, very useful when the submission to be made is via mail cause you can always reason that I mailed the correct file ūüėČ .

Link here

I personally tried with a Doc file and it worked good. No traces left, seriously. Word says that the file seems to be corrupted and doesn’t open at all.!

Who says the technology era would enhance our capabilities and we would work more synchronously.! It always break down to our choice.. ūüôā

Firefox great addon

October 28, 2010

Today, i kind of stumbled upon a really good fireox addon name AddThis.. It is really a good addon for people who have to manage many accounts.. The services supported by it are gigantic, didn’t even knew that these many existed..!!

Use this if you are a firefox user: AddThis

Else go to: AddThis

great chrome extension to stay connected all the time

October 26, 2010

Also available for other browsers…

via Search for wordpress on the Google Chrome extension gallery. page 1.


%d bloggers like this: