01110100110101010101011101100010
Posts tagged Python
Begining Python workshop
Jan 27th
LUG Manipal is organising a workshop on python, Workshop is aimed at people interested in beginning programming with python.No programming experience required.
Details are ->
Time: 5:30 pm
Place: NLH 103
Date: 29th JAN to 3rd FEB
PS :- Slides for the workshop are available Begining Python Slides
A simple python socket chat example
Jul 30th
i was trying to explain sockets to one of my friend and this is what i used, the code should be self explanatory, this is a very simple application of sockets…
download here
Get updates of completed torrents via SMS
Apr 6th
This Sunday when i was giving DBUS a look and thinking about all the cool things possible with it, one of my friend came asking how can he control his torrents from anywhere and i thought controlling is ok, do you want SMS updates??, i fired up qdbusviewer and there it was a simple way to get sms notifications of finished torrents using well twitter and ktorrent, so here are the steps
1) setup your cell phone to recieve SMS updates in twitter,
2) get one more twitter account lets say ktorrent, follow ktorrent and turn device updates on,
3) now save the script below say as torrenttwit.py
4) now enter this ktorrent account username and password in the script below,
5) start ktorrent if not already started, now run the script by typing “python torrenttwit.py”
import dbus,base64,urllib2,urllib
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
username="username"
password="password"
def tweet(msg):
request = urllib2.Request('http://twitter.com/statuses/update.json')
request.add_header('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (username,password))[:-1])
request.add_data(urllib.urlencode({'status': msg.encode('utf-8')}))
opener = urllib2.build_opener()
req= opener.open(request)
s = dbus.SessionBus()
kt = s.get_object("org.ktorrent.ktorrent","/core")
def update(k):
torrent = s.get_object("org.ktorrent.ktorrent","/torrent/"+k)
name = torrent.get_dbus_method("name","org.ktorrent.torrent")
tweet("ktorrent: finished " +name())
kt.connect_to_signal("finished",update)
import gobject
loop = gobject.MainLoop()
loop.run()
you are done, now whenever a torrent finishes the script will twit and you will receive an SMS update
enjoy
LUG Manipal’s Python Workshop
Jan 26th
LUG Manipal is organising a workshop on Python, which is a dynamic object-oriented programming language that can be used for many kinds of software development. It runs on Windows, Linux/Unix, Mac OS X, OS/2, Amiga, Palm Handhelds, and Nokia mobile phones. It comes with extensive standard libraries, and can be learned in a few days.
The workshop requires no prerequisites, even knowledge of C is not required, it is aimed at people interested in beginning programming with Python.
There is no charge for the workshop and no registration is required, everyone is invited.
People using Windows are requested to Install the Following Software before coming to the workshop
1) Python 2.6.1 from here
2) Notepad++ from here
Note: These will also be distributed on the first day of the workshop, If you are not able to install/download them you can get them there…
Perl, Django and hopefully a new blog
Dec 21st
Almost 15days have passed since my vacations and i am really enjoying it, i get great Home cooked Food, enjoy pastries and stuff form a not so far bakery can sleep for as much as i want ( which is mostly around 7-9 hrs ) spend my whole time watching Movies, Series and Learning new things and well my results are out got more GPA then what i got till now with attending around half the classes in a regular sem because of the attendances that i got….
Now talking about the Important Things, What All i have Done Till now
Perl – after asking many people about how to begin with Perl and hearing all sorts of answers i finally decided its time for me to go for it, So in Bangalore i bought myself the Llama Book and started Perl, the Llama Book from what i feel is perfect for beginning Perl it clearly explains everything and after that you have Google to help to everywhere. So i now can say happily that i know Basic Perl
And well after that i started with Django and i really like it at first MTV (Model Template View) seemed strange but i got it looks gr8, so after my new found love for Django i wanted to shift my blog from wordpress to Django but was not able to find anything that would allow me setup a simple blog, so i have started writing code for my own blog and write now trying to find a way for importing existing wordpress entries to my blog and hope to release the code as soon it starts working without a glitch and move to it, i am plannig to keep compatibility all the post urls if someone has got some link to my wordpress blog they wont break…..
MobiVision, Techtatva 08, LUG Manipal and lots more….
Oct 20th
I am posting to my blog after a long long time and a lot has happened, first Lets start with MobiVision.
MobiVision (Brain child of Subhendra Bhaiya) was a workshop conducted by people from LUG Manipal ( well not officially but everyone involved in it was from LUG Manipal ) as the name suggests it was on developing Application for mobile Plateform, basicly targeting Python for Series 60 and Android, We were expecting turnout of around 100 people and more the double turnout took us by surprise, it saw a partisipation of over 200 which comprised of guys/gals from First to Fourth year which was really amazing we even had people doing PG showing Interest, we had some trouble managing them in 2 rooms which were alloted to us but in the end every thing turned out pretty well. We had 2 Teams ready one for Python S60 and one for Android, Both teams did a great job and made Mobivision the most sucessfull Workshop in Techtatva 08.
Next was Techtatva 08 which is the annual Technical Fest of Manipal Institue of Technology, Manipal, Here again LUG Manipal was in full control ( and again not officially!!! ) we were to conduct events for the Computer / IT Catagory called ” PARAM ” and we planned to change the previously conducted events so as to make them fit in the 4 basic catagories of people –
1) ” MobiVision ” for Inovators here teams where to come up with a inovative Idea for Mobile Application and a prototype
2) ” Jour ” for Developers here teams were to make any one of the three Projects and give a Presentation and Demonstration of their product
3) ” CodeBytes ” for Programers the usual problem solving event with not so usual questions
4) ” Puzzle Mania ” for Every Day internet users comprising of all sorts of Puzzels
all the events saw good participation from all years and were prased for not having a single glitch.
I also made a Deligate and Event Registration system for managing and registering all the people coming for Techtatva 08 and also a CBT ( Computer Based Test ) system for priliminary rounds of some events, it was all basicly made in PHP and used MySQL as primary Database and was hosted on a Fedora 9 ( for those of you who dont know what it is — Its a GNU/Linux Distribution and also my Primary OS ) based server running Apache in Student Councels room because we/I were/was denined permition to host it on the main Manipal University server, they said “You are a Threat for our Network!!!” ??? which left me wonder what kind of stuff they do there and what did i do to them??? ( reason for which i got to know later ) anyways we managed to get a lab computer for using as a server, it had a AMD Athlon x3800 CPU, 80 GB HDD and 1GB RAM, which was all i needed for my work, the PC was formatted and fresh Fedora 9 was installed on it, after this all updates were applied which didn’t took much time as the connection there is not at all like I-ON and is at least 10 times faster ( well it was MAHE LAN and I-ON is WiFi but still!!! ) some changes in http.conf and iptables and it was ready. The System ran without a glitouch except when someone made the LAN cable for the server loose which made all on Registration Desks shouting but luckly everything was back online in 2-3 mins. The CBT’s also ran very good and results were decleared as soon as the alloted time was over and there were no objections.
Well this is enough for a post now 3rd Sessionals are approaching and i need to study as i screwed my 2nd sessionals, so bye
Ankur Shrivastava
Ion Auto Login script in Python
Sep 16th
i was just thinking about making the very famous IAL script of DJ in python and here is it and its damn simple
import urllib, urllib2, time
username = "Your username"
password = "Your Password"
interval = 10
data = {"loginID":username,"loginpassword":password,"flag":"0","popcheck":"0","submit":"Sign In"}
value = urllib.urlencode(data)
request = urllib2.Request("http://192.168.150.2:8080/clntAuth/clntAuth_main.jsp",value)
print "Logging In\nMade by Ankur - http://ankurs.com"
while (1):
open = urllib2.urlopen(request)
responce = open.read()
for i in range (1,interval):
print (interval-i),"min Till Next Login"
time.sleep(60)
print "Logging In\nMade by Ankur - http://ankurs.com"
or downlaod
run it by typing python ial.py
it uses urllib, urllib2 and time which are the default module, you have to change the username and password to your username and password, changing the interval changes the time interval in which auto login takes place. enjoy!!
PS – current it does no check if your connection is active or not, will add that soon
Creating a Simple Chat Application with Python
May 1st
Creating application with Python is very simple, here is a simple chat application made by using the socket module, it has 2 parts First Server and Second client, you run the server first and then connect the client to it, here is the code
Here is the Server Code
#!/usr/bin/env python
from socket import *
from time import time, ctime
IP = ''
PORT = 23456
ADS = (IP, PORT)
tcpsoc = socket(AF_INET, SOCK_STREAM)
tcpsoc.bind(ADS)
tcpsoc.listen(5)
while 1:
print "Waiting for connection"
tcpcli, addr = tcpsoc.accept()
print "connected from:", addr
while 1:
data = tcpcli.recv(1024)
if not data : break
print data
data1 = raw_input(">>")
if data1 == "q;t": break
tcpcli.send(data1)
tcpcli.close()
tcpsoc.close()
Here is the client code
#!/usr/bin/env python
from socket import *
IP = ''
PORT = 23456
ADS = (IP, PORT)
tcpsoc = socket(AF_INET, SOCK_STREAM)
tcpsoc.connect(ADS)
while 1:
data = raw_input("msg>>")
if not data : break
tcpsoc.send(data)
data = tcpsoc.recv(1024)
if not data: break
print data
tcpsoc.close()
the code above might not be properly intended so you can download the code from http://fb.ankurs.com/tcp_server.py and http://fb.ankurs.com/tcp_client.py
enjoy!!!
Google announces AppEngine
Apr 8th
GoogleCode at their second CampFireOne announced App Engine a developer tool that enables anyone to run their web applications on Google’s infrastructure , which will be a closed beta with with only 10000 developers having access on first come first serve basis. its similar to AWS (Amazon Web Services) but takes every thing further. Google App Engine applications are implemented using the Python programming language. The runtime environment includes the full Python language and most of the Python standard library. App Engine also includes a scalable datastore, Django templating system and an open-source Python logging system. Its also provides authentication, analytics and access to Google service APIs. There is also a SDK available for local development. It also has the ability to move apps to the web in just a single command.
Google will also provide 500 MBs of storage and enough bandwidth and processing power to serve 5 Million pages per month along with a free subdomain on appspot.com or you can also use google apps to server the app on your domain
If you’d like to try it out, sign up for access to the preview release (well 10,000 limit has been reached sry hard luck) but you can download the SDK and try building the apps locally till you get an invite. You can also check out their blog http://googleappengine.blogspot.com/ for more updates and info











