Saturday 28 October 2017

Sara - A virtual assisstant made in python

Have you ever wondered about building your own virtual assistant? Off course who might have not, specifically something like Jarvis. Now you can too with Python and other languages with their rich libraries at your disposal.Here is my small glimpse of what can be done in Python. I have made my assistant(Sara) with very limited features to start off with. Features would be kept on adding and your help would be appreciated always as it is licensed under GPLv2. Also you can tinker around with it to make your own assistant styled according to you as it is under GPLv2.
Hope you like it.
It is available at https://github.com/SubrataSarkar32/sara
Here is a vedio below:

Tuesday 11 April 2017

pdecrypt(Python:Simple Caesar Cipher)

Ever felt the need to encrypt text data. Now do it easily using pdencrypt(works on simple caesar cipher).This is a python program. After creating a file you would like to keep the python with you so that no one gets clue.Can be considered public domain work.You responsible for using the software properly You take liability of storing your own data and protecting it Programmer is not responsible for mistakes on part of user. If you have any suggestions feel free to coment.
Sorry small update for typo erors:
import string
name=raw_input('Enter file name: ')
def entangle(t):
    key=13
    lock=string.printable
    ret=''
    for wor in t:
        po=lock.find(wor)
        if po+key>=len(lock):
            po=((po+key)-(len(lock)-1))-1
        else:
            po+=key
        ret+=lock[po]
    return ret
def disentangle(t):
    key=13
    lock=string.printable
    ret=''
    for wor in t:
        po=lock.find(wor)
        if po-key<0:
            po=len(lock)+(po-key)
        else:
            po-=key
        ret+=lock[po]
    return ret

def read(name):
    file1=open(name,'r+')
    op=file1.readlines()
    for obj in op:
        obj=disentangle(obj)
        print obj
    file1.close()
def write(name):
    file1=open(name,'r+')
    t=raw_input('Enter ;')
    t=entangle(t)
    prev=file1.read()
    wr=prev+t+'\n'
    file1.close()
    file1=open(name,'w+')
    file1.write(wr)
    file1.close()
def main(name):
    file1=open(name,'r+')
    keyi=file1.readline()
    file1.close()
    key=raw_input('Enter your key: ')
    if key==disentangle(keyi[:-1]):
        while True:
            choi=raw_input('choice:')
            if choi=='1':
                read(name)
            elif choi=='2':
                write(name)
            elif choi=='3':
                break
            else:
                print 'invalid input'
                print 'program quitting'
                file1=open(name,'r+')
                prev=file1.read()
                wr=prev+'\n'
                file1.close()
                file1=open(entangle(name)+'.tri','w+')
                file1.write(wr)
                file1.close()
                file1=open(name,'w+')
                file1.write(name)
                file1.close()
    else:
        print 'Warning!! do not interfere encrypted txt'
        file1=open(name,'r+')
        prev=file1.read()
        wr=prev+'\n'+entangle('Warning!Someone tried to access your file')+'\n'
        file1.close()
def run():
    import os
    if os.path.isfile(name):
        main(name)
    else:
        file1=open(name,'w+')
        print 'This is important!!'
        print 'Your key is being set.'
        print 'You must remember this else your information stored is doomed'
        import random
        k=random.randint(10,len(string.printable)-1)
        print 'Your key is ',k
        stor=entangle(str(k))+'\n'
        file1.write(stor)
        file1.close()
        main(name)
run()

Saturday 18 February 2017

Facebook+Python=Awesome

Do you like python? Do you use facebook?
If the answer is yes why not use facebook via python.
Below is the code to use facebook via python .This program has been inspired by http://www.geeksforgeeks.org/send-message-to-fb-friend-using-python
 Disclaimer of Warranties and Limitation of Liability.
a.Unless otherwise separately undertaken by the author, to the extent possible, the author offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
b.The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
Check out fbchat's policies before continuing.
# This code to be considered under GPLv3.Use it under your responsibility.
Code:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#Please use it carefully.Ensure loging out by using a browser
#Required dependencies:
#   requests
#   lxml
#   beautifulsoup4
#   fbchat
def main():
    '''main function: initiation of fbchat and login'''
    import fbchat
    from getpass import getpass
    username = str(raw_input("Username: "))
    client = fbchat.Client(username, getpass())
    '''
    #For sendig same message to specific number of clients
    no_of_friends = int(raw_input("Number of friends: "))
    for i in xrange(no_of_friends):
        name = str(raw_input("Name: "))
        friends = client.getUsers(name)  # return a list of names
        friend = friends[0]
        msg = str(raw_input("Message: "))
        ask = 'O'
        while ask.upper()!='Y' and ask.upper()!='N':
            ask = raw_input('Are you sure about sending this message to'+friend+'(Y/N):')
            if ask.upper()=='Y':
                sent = client.send(friend.uid, msg)
                if sent:
                    print("Message sent successfully!")
            elif ask.upper()=='N':
                print("Message was not sent .")'''
    def choicefrnd(friends):
        '''choose freind from list'''
        try:
             chno=input('Enter index of friend: ')
             friend = friends[chno-1]
             return friend
         except:
             print 'Please give index number as printed above from 1 to n'
             choicefrnd()
    def talk():
        '''talk with friends. Contains main loop and sub loops'''
        ch='y'
        while ch=='y':   
            name = str(raw_input("Name: "))
            friends = client.getUsers(name)  # return a list of names
            for i in xrange(len(friends)):
                print str(i+1)+str(friend[i])
            if len(friends)>=1:
                friend=choicefrnd(friends)
                msg = str(raw_input("Message: "))
                ask = 'O'
                while ask.upper()!='Q':
                   
                    ask = raw_input('Are you sure about sending this message to'+friend+'(Y/N):')
                    if ask.upper()=='Y':
                        sent = client.send(friend.uid, msg)
                        if sent:
                            print("Message sent successfully!")
                    elif ask.upper()=='N':
                        print("Message was not sent .")
                    elif ask.upper()=='Q':
                        break
                    else:
                        print 'Could not decipher your answer.'
                    print 'Press q to quit chatting this friend'
            else:
                pass           
        else:
            pass
        talk()
        client.logout()
main()

AI in 2040