My first git push :)

Standard

Finally managed my first git push. Phew!!! Although the work is not complete but still I am happy that I could present atleast something out of nothing and with not-so-much knowledge about python.
So what i did for my first open source project is that I made an application, a System-Monitor that would monitor the CPU, RAM and DISK usage and plot dynamic graphs accordingly.
Of course I used dependencies. I used psutil to extract the data, matplotlib to plot the dynamic graphs and gtk to create my own window (Currently the gtk feature is not available. I am using matplotlib window until I learn to use gtk).
So, as Kushal Das, my mentor, instructed me to create a file data.py to extract the info, I did so using psutil.
Next, there is the main.py which plots the graphs using matplotlib and displays them in a matplotlib window.
The work is not complete yet. I still need to write setup.py to make a command to run the program directly from the terminal. Will update when things are done.
This is the link to the git repository: https://github.com/desouradeep/System-Monitor
I have also included some screenshots, hope you like them. ūüėÄ
I would also like to thank Sayan Chowdhury for helping me out. ūüôā

THE CODE :

1. data.py

import psutil
def cpu():
    '''This method returns the current CPU usage'''
    a=psutil.cpu_percent(interval =0.1, percpu=False)
    return "%4.2f" %a
def mem():
    '''This method returns the current RAM usage'''
    a=psutil.phymem_usage().percent
    return "%2.2f" %a
def dsk():
    '''This method returns the current DISK usage'''
    a=psutil.disk_partitions()
    b=[]
    x=0
    y=0
    for i in range (0,len(a)):
        b.append(a[i][1])
        x+=psutil.disk_usage(b[i])[0]
        y+=psutil.disk_usage(b[i])[1]
        z=float(y)/float(x)*100
    return "%2.2f" %z

2.main.py

#!/usr/bin/env python
import matplotlib.pyplot as plt
import matplotlib
import data
c=[]
m=[]
d=[]

def main():
    print 'NO.	CPU	MEMORY	DISK'
    plt.subplot(211)
    i=0
    while True:
        i+=1
        plt.ylim(0,100)
        plt.xlim(0,60)
        cc=data.cpu()
        mm=data.mem()
        dd=data.dsk()
        print i,'\t',cc,'\t',mm,'\t',dd
        c.append(cc)
        m.append(mm)
        d.append(dd)
        plt.grid(True)
        plt.xlabel('TIME')
        plt.ylabel('USAGE IN %')

        plt.title(' - - SYSTEM MONITOR - - ')
        ds='DISK ('+dd+'%)'
        ms='RAM  ('+mm+'%)'
        cs='CPU  ('+cc+'%)'
        plt.plot(d[-60:-1],'g', label=ds)
        plt.plot(m[-60:-1],'r', label=ms)
        plt.plot(c[-60:-1],'b', label=cs)
        plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.06,0,0.04), ncol=3)
        if len(c)>60:
	        del c[0]
	        del m[0]
	        del d[0]
        plt.draw()
        matplotlib.interactive(True)
        plt.show()
        plt.clf()

main()

Here are some of the screenshots:

This slideshow requires JavaScript.

My first FOSS project :)

Standard

Started working on my first FOSS project. I chose python as my language for making a CPU, RAM performance viewer app in linux fedora which would use dynamically updated graphs of CPU and RAM usage.
Things are a bit complicated, as of now. Initially, I thought of using matplotlib library to plot the graphs but now I find that it only exports the image without displaying it.
Having a tough time working to get around the graphical part, other than that, extraction was a piece of cake since I used psutil module.

Python Program to dislay company share value from Yahoo! finance.

Standard

This one was given by kushal few days back to get acquainted with the urllib.
The objective was to take in a company symbol and print its current share value from Yahoo! finance.
This was my piece of code:

#!/usr/bin/env python
import urllib
a=raw_input('Enter  SYMBOL       : ')
url='http://finance.yahoo.com/q?s='+a+'&ql=1/'
con=urllib.urlopen(url)
if con.geturl().find('lookup')!=-1:
    print 'INVALID SYMBOL!!! Program will exit.'
    exit(0)
s=con.read()
search='tabledata1">'
i=s.find(search)
l=len(search)
i+=1
x=0
val=''
while(s[i].isdigit() or s[i]=='.' or s[i]==','):
    val=val+s[i]
    i+=1
a=s.find('title')+6
sum=''
while(s[a]!='<'):
    sum=sum+s[a]
    a+=1
print sum
print 'Current share value :',val

These were some of the test outputs…

[souradeep@souradeep Documents]$ chmod +x symbol.py
[souradeep@souradeep Documents]$ ./symbol.py
Enter  SYMBOL       : DELL
DELL: Summary for Dell Inc.- Yahoo! Finance
Current share value : 12.27
[souradeep@souradeep Documents]$ ./symbol.py
Enter  SYMBOL       : RHT
RHT: Summary for Red Hat, Inc. Common Stock- Yahoo! Finance
Current share value : 51.16
[souradeep@souradeep Documents]$ ./symbol.py
Enter  SYMBOL       : ORCL
ORCL: Summary for Oracle Corporation- Yahoo! Finance
Current share value : 29.10
[souradeep@souradeep Documents]$ ./symbol.py
Enter  SYMBOL       : SDE
INVALID SYMBOL!!! Program will exit.

I really enjoyed the program…my first one with the urllib.