Notification App

Add this program to startup program. It will will show you some Movies Quotes after Each 30 min. Even If you are offline (condition is that if there are few quotes alredy stored in Mongodb databse).

Application Name :Movies_Famous_Quotes

auther="Sudhanshu Patel"


In [1]:
import ctypes  # An included library with Python install.
from pymongo import MongoClient
import pymongo
import unirest
import json
import Tkinter, tkMessageBox
from random import randint
import time
import winsound
import pyttsx  #sound
from Tkinter import *

In [2]:
#Configure Unirest
unirest.timeout(8)

Storing To Database

One Time Specification for uniqe quotes
Done this using Shell

  • open CMD
  • mongo
  • show db
  • select Quote
  • show collections
  • db.movies.createIndex( { quote: 1 }, { unique: true, sparse: true } )

In [3]:
class TheQuotes():
    def __init__(self,):
        
        self.data=False
        #Configure Voice
        self.engine = pyttsx.init()
        self.engine.setProperty('voice', u'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\TTS_MS_EN-GB_HAZEL_10.0')
        self.rate = self.engine.getProperty('rate')
        self.engine.setProperty('rate', self.rate+60) #regulate speed of speaking
        
        #configure GUI
        #self.root = Tkinter.Tk()
        #self.root.withdraw()
        
        
        #databse
        self.client=MongoClient()
        self.db=self.client["Quote"]
    
    def query(self):
        "Querying on server"
        try:
            return json.loads(unirest.post("https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies",
                                headers={
                    "X-Mashape-Key": "4qbGQ73WKZmshpkmiExFtO3wlQsIp1ve1nOjsn0RQRy67VAlWg",
                    "Content-Type": "application/x-www-form-urlencoded",
                    "Accept": "application/json"
                }).raw_body)
        except:
            return False
    def insert(self):
        try:
            self.db.movies.insert_one(self.data)
        except:
            print "Error in insert"
    def draw(self):
        #Popup & sound
        #engine = pyttsx.init()
        self.engine.say(self.data['quote']+'\n-from '+self.data['author'])
        #tkMessageBox.showinfo("Time to RuN", self.data['quote']+'\n-from '+self.data['author'])
        self.engine.runAndWait() 
        
        root = Tk()
        text1 = Text(root, height=50, width=70)
        photo=PhotoImage(file='./output_aOHcbJ.gif')
        text1.insert(END,'\n')
        text1.image_create(END, image=photo)

        text1.pack(side=LEFT)

        text2 = Text(root, height=50, width=70)
        scroll = Scrollbar(root, command=text2.yview)
        text2.configure(yscrollcommand=scroll.set)
        text2.tag_configure('bold_italics', font=('Arial', 16, 'bold', 'italic'))
        text2.tag_configure('big', font=('Verdana', 25, 'bold'))
        text2.tag_configure('color', foreground='#476042', 
						font=('Tempus Sans ITC', 16, 'bold'))
        text2.tag_bind('follow', '<1>', lambda e, t=text2: t.insert(END, "\t\t--By Sudhanshu Patel\n www.codecops.in"))
        text2.insert(END,'\n\n\t'+self.data['author']+"\n\n", 'big')
        quote = " "+self.data['quote']+"\n\t"
        text2.insert(END, quote, 'color')
        text2.insert(END, 'follow-up\n', 'follow')
        text2.pack(side=LEFT)
        scroll.pack(side=RIGHT, fill=Y)

        root.mainloop()
        
    def slectFrom_DB(self):
        "select random from database"
        return self.db.movies.find().limit(-1).skip(randint(0,self.db.movies.count()-1)).next()

In [ ]:
if __name__=='__main__':
    ## Loop Work
    obj=TheQuotes()
    while True:
        obj.data=obj.query()
        if obj.data !=False:
            obj.insert()
        else:
            obj.data=obj.slectFrom_DB()
        winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
        obj.draw()
        obj.data=False
        time.sleep(15)#162000) #process repeate After Each 45 Min


Error in insert
Error in insert
Error in insert

In [ ]: