Skip to content

Commit

Permalink
More python programs
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Apr 30, 2018
1 parent a04de22 commit 1b0d6cb
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 12 deletions.
3 changes: 1 addition & 2 deletions database/insert_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
# Licence: MIT
#-------------------------------------------------------------------------------
import MySQLdb

db = MySQLdb.connect("localhost","root","ramji","cable")
cursor = db.cursor();
cursor = db.cursor()
sql ="insert into customer values(20,'rakesh','jagdish','cf-4 arun vihar','12121212','[email protected]');"
cursor.execute(sql)
db.close()
Expand Down
6 changes: 0 additions & 6 deletions database/mysql_connection.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@

#-------------------------------------------------------------------------------
import MySQLdb


# Open database connection
db = MySQLdb.connect("localhost","root","ramji","cable" )

# prepare a cursor object using cursor() method
cursor = db.cursor()

# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")

# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print("Database version : %s " % data )

# disconnect from server
db.close()
2 changes: 1 addition & 1 deletion database/select_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import MySQLdb
# Open database connection
db = MySQLdb.connect("localhost","root","ramji","cable" )
cursor = db.cursor();
cursor = db.cursor()
sql ="select * from customer"
cursor.execute(sql)
results = cursor.fetchall()
Expand Down
2 changes: 1 addition & 1 deletion delete All File with extension_EXE.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():
root.withdraw()
directory = filedialog.askdirectory() #source folder
count=0
for root,files in os.walk(directory):
for root, SubFolders , files in os.walk(directory):
os.chdir(root)
files = glob.glob('*.exe')
for filename in files:
Expand Down
10 changes: 10 additions & 0 deletions error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sum = 0
for i in range(10):
try:
if 10 / i == 2:
break
except ZeroDivisionError:
sum = sum+1
else:
sum = sum +2
print("Sum :",sum)
2 changes: 1 addition & 1 deletion fileHandling/file_read.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file = open(r"C:\Users\acer\Desktop\pythonPrograms\fileHandling\abcd.txt",'r')
file = open(r"C:\Users\acer\Desktop\PythonBox\pythonPrograms\fileHandling\abcd.txt",'r')
data1 = file.read()
print(data1)
file.close()
44 changes: 44 additions & 0 deletions gre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from bs4 import BeautifulSoup
from random import randint
import urllib
import pynotify
import time


def sendMessage(title, message):
pynotify.init("Test")
notice = pynotify.Notification(title, message)
notice.show()
return

webpage = urllib.urlopen('https://quizlet.com/58647605/kaplan-900-flash-cards').read()

# Parse the entire webpage
soup = BeautifulSoup(webpage)

word = []
meaning = []

# Scrape words from soup
for words in soup.find_all("span", class_="TermText qWord lang-en"):
# Convert ascii to string
word.append(words.text.encode("utf-8"))

# Scrape meanings from soup
for meanings in soup.find_all("span", class_="TermText qDef lang-en"):
meaning.append(meanings.text.encode("utf-8"))

print("Churning words !")


while(1):
index = randint(0,700)
print(index)
# First just pop the word on screen to wait for response
sendMessage(word[index],"")
# Adjust the response time between word and its meaning
time.sleep(15)
# Display the meaning with the word
sendMessage(word[index], meaning[index])
# Time after which a new word pops on screen
time.sleep(600)
3 changes: 3 additions & 0 deletions list_idea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
list = [1, 1, 2, 3, 5, 8, 13]
print(list[list[4]])

Empty file added list_idea1.py
Empty file.
42 changes: 42 additions & 0 deletions newsfeed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
-*- coding: utf-8 -*-
========================
Python Desktop News Notifier
========================
Developed by: Chirag Rathod (Srce Cde)
Email: [email protected]
========================
"""

import feedparser
import notify2
import time
import os


def Parsefeed():
f = feedparser.parse("http://feeds.bbci.co.uk/news/rss.xml")
ICON_PATH = os.getcwd() + "/icon.ico"
notify2.init('News Notify')

for newsitem in f['items']:
print(newsitem['title'])
print(newsitem['summary'])
print('\n')

n = notify2.Notification(newsitem['title'],
newsitem['summary'],
icon=ICON_PATH
)

n.set_urgency(notify2.URGENCY_NORMAL)
n.show()
n.set_timeout(15000)
time.sleep(1200)


if __name__ == '__main__':
try:
Parsefeed()
except:
print("Error")
10 changes: 10 additions & 0 deletions turtlePrg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
36 changes: 36 additions & 0 deletions webscraper/news_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

#importing necessary modules.
import bs4 as bs
import urllib.request
from gtts import gTTS
import vlc
import time
from mutagen.mp3 import MP3

#defining function to play sound.
def reader(s):
tts = gTTS(text=s, lang='en')
tts.save("greeting.mp3") #saving as mp3 file
p = vlc.MediaPlayer("greeting.mp3") #loading to media player
f = MP3("greeting.mp3")
n = f.info.length #getting duration of sound file
p.play() #Playing sound
time.sleep(n) #Sleeping for sub subprocess to take place

#connecting to news site
sauce = urllib.request.urlopen('https://news.google.co.in/').read()
soup = bs.BeautifulSoup(sauce,'lxml')
b=soup.body
y=''
m=''

m="hello boss, you should check out following news \n"
reader(m)

#Webscraping text news with class esc-lead-title-wrapper
for x in b.find_all("div", class_="esc-lead-article-title-wrapper"):
y="\n"+x.text+"\n"
reader(y)

m=" \nThank you. that's all for the news today \n "
reader(m)
12 changes: 12 additions & 0 deletions webscraper/nscPrice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import requests
import webbrowser
from bs4 import BeautifulSoup

url ="http://www.moneycontrol.com/india/stockpricequote/banks-private-sector/idfcbank/IDF01"
site = requests.get(url)
#print(site.text)
soup = BeautifulSoup(site.text,"html.parser")
for link in soup.select('#Nsc_Prc_tick_div'):
print(link)
name = link.get('strong')
print(name)
35 changes: 35 additions & 0 deletions webscraper/timeofindia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from bs4 import BeautifulSoup
import subprocess
import requests
import time

url = "https://timesofindia.indiatimes.com/"

def open_url(url):
return requests.get(url).text # returns html

def get_bsoup_object(html):
return BeautifulSoup(html, "lxml") # returns soup (BeautifulSoup's object)


def sendmessage(message):
subprocess.Popen(['notepad.exe', message])
return


def main():
myhtml = open_url(url)
soup = get_bsoup_object(myhtml)
j = 1

for i in soup.find('ul',attrs={'class':'list9'}).findAll('li'):
#print(str(j) + " " + i.text)
sendmessage(str(j) + " " + i.text)
time.sleep(10)
j += 1



while True:
main()
time.sleep(36000)
2 changes: 1 addition & 1 deletion webscraper/youtubeDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import shutil
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=v8g9arm8nFI&list=PL9rywNkH9WIPqi-YhUlq_pCYaqE0HyaQs'])
ydl.download(['https://www.youtube.com/watch?v=e2D-kjOMNF0'])
1 change: 1 addition & 0 deletions zen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import this

0 comments on commit 1b0d6cb

Please sign in to comment.