├── .travis.yml ├── CONTRIBUTING.md ├── Codechef_automation_bot ├── README.md ├── assets │ ├── show_pic1.png │ ├── show_pic2.png │ ├── show_pic3.png │ ├── show_pic5.png │ ├── show_pic6.png │ ├── show_pic7.png │ ├── show_pic8.png │ ├── submit_pic1.png │ ├── submit_pic2.png │ ├── testPic3.png │ ├── test_pic2.png │ ├── testing_pic.png │ └── tree_structure.png ├── chromedriver ├── requirements.txt ├── setup.py ├── submit.py ├── template.cpp └── test.py ├── KS ├── 1. fetch data.PNG ├── 1. fetch.PNG ├── MAIN APP │ ├── address.py │ ├── address.pyc │ ├── check_date.py │ ├── dol_extractor.py │ ├── dol_extractor.pyc │ ├── filters.py │ ├── filters.pyc │ ├── info.py │ ├── info.pyc │ ├── name.py │ ├── name.pyc │ ├── new_app.py │ ├── remove_sig.py │ ├── remove_sig.pyc │ ├── stopwords_filter.py │ └── stopwords_filter.pyc ├── MAIN APP_after.zip ├── MAIN APP_after │ ├── MAIN APP │ │ ├── address.py │ │ ├── address.pyc │ │ ├── filters.py │ │ ├── filters.pyc │ │ ├── info.py │ │ ├── info.pyc │ │ ├── name.py │ │ ├── name.pyc │ │ ├── name_extractor.py │ │ ├── name_extractor.pyc │ │ ├── new_app.py │ │ ├── remove_sig.py │ │ ├── remove_sig.pyc │ │ ├── stopwords_filter.py │ │ └── stopwords_filter.pyc │ ├── app_re_GS.zip │ ├── main_app_3.zip │ └── main_app_name2.zip ├── MAIN_APP_before.zip ├── MAIN_APP_before │ ├── address.py │ ├── address.pyc │ ├── filters.py │ ├── filters.pyc │ ├── info.py │ ├── info.pyc │ ├── name.py │ ├── name.pyc │ ├── new_app.py │ ├── remove_sig.py │ ├── remove_sig.pyc │ ├── stopwords_filter.py │ └── stopwords_filter.pyc ├── address.pyc ├── app.py ├── check_sig.py ├── checks │ ├── address.py │ ├── name.py │ ├── new_names.py │ ├── sig.py │ ├── sig_ml.py │ └── xiny.py ├── info.pyc ├── info_states │ └── dict.py ├── main_app_dol.zip ├── modified.py ├── name.pyc ├── new.py ├── new_app │ ├── address.py │ ├── info.py │ ├── name.py │ ├── new_app.py │ └── remove_sig.py ├── new_app_2.zip ├── phoneno.py ├── problem.PNG ├── remove_sig.pyc ├── test case.docx └── unwanted_names.py ├── README.md ├── app.py ├── clap_activated_switch_arduino ├── cleverbot.py ├── codechef_submission.py ├── earthquake.py ├── exchange_rates.py ├── fakeuser.py ├── full-contact.py ├── googletranslate.py ├── hiQ ├── bruno_mars.py └── gaana.py ├── ipl.py ├── kiara.py ├── loremipsum.py ├── mail_parser.py ├── pokeapi.py ├── quora.py ├── requirement.txt ├── trending_tweet_db ├── get_trending.py └── tweet_db.db ├── vurl.py ├── whatsapp-web-send-message.py ├── wiki-crawler.py ├── wolfram_bot.py ├── worldtime.py ├── youtube.py ├── youtubeTrailers.py └── youtubecrawl.py /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.5.2" 4 | install: 5 | - pip install -r requirement.txt 6 | script: 7 | - python quora.py how to learn algo 1 n 8 | sudo: required 9 | branches: 10 | only: 11 | - master 12 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | You can add your own favorite automation scripts 2 | Keeping in mind the readability of the code 😉 3 | -------------------------------------------------------------------------------- /Codechef_automation_bot/README.md: -------------------------------------------------------------------------------- 1 | # Use Case 2 | This bot reduces the menial work that has to be done before and during the contests. And makes you more productive while doing contests. 3 | 4 | # How to install the bot: 5 | - First clone the repository into a directory of your choice. 6 | - To run this bot **python3** is necessary. If you don't have python3 [click this link to download](https://www.python.org/downloads/) 7 | - Navigate to the directory in which you cloned the repository and open the terminal in the same path. 8 | - run the command 9 | For windows users: 10 | ```shell 11 | pip install -r requirements.txt 12 | ``` 13 | For mac or linux users: 14 | ```shell 15 | pip3 install -r requirements.txt 16 | ``` 17 | # How to use it: 18 | - To participate in a contest: 19 | - Just run the setup.py file. It is a interactive program all the details needed will be prompted by the program. 20 | - The program will create a directory in the specifed directory and will create subDirectories for all the problems in a contest. The tree structure will be like. 21 | ![](assets/tree_structure.png) 22 | - The files in those directories are: 23 | - **statment.txt:** contains the problem statment. 24 | - **given_input.dat:** Contains the sample input of the problem. 25 | - **given_output.dat**: Contains the sample output of the problem. 26 | - **sol.cpp:** Contains a basic template in which you have to write the solution of the problem. 27 | - **test.py:** When you run this program your code will be tested against the sample input testcases.You can check your output in yourOut.dat file.*(If you are a windows user check out the **note** below).* 28 | - **submit.py:** When you run this program the code you wrote will be submitted to the online judge and the results will be printed on your terminal. 29 | - Now using this bot you can solve problems without having the hassle of doing all the jobs manually from the browser. 30 | 31 | ## Commands for running: 32 | In Windows: 33 | ```shell 34 | python (filename) 35 | ``` 36 | In linux or macOS: 37 | ```shell 38 | python3 (filename) 39 | ``` 40 | ### Note: 41 | - when you are running the test.py file it may not work in a windows system to make it work you have to install the g++ compiler [checkout this link to see how to download and install g++ compiler](https://youtu.be/sXW2VLrQ3Bs). 42 | - The *template.cpp* file in your cloned repository. Is from where the *sol.cpp* files are copied if you want to use your own template instead of the default you can replace the *template.cpp* file with your own template code. 43 | 44 | 45 | ## Screenshots: 46 | ### Creating contest pics: 47 | ![](assets/show_pic1.png) 48 | ![](assets/show_pic2.png) 49 | ![](assets/show_pic3.png) 50 | ![](assets/show_pic4.png) 51 | ![](assets/show_pic5.png) 52 | ![](assets/show_pic6.png) 53 | ![](assets/show_pic7.png) 54 | ![](assets/show_pic8.png) 55 | ### Testing solution pics: 56 | ![](assets/testing_pic.png) 57 | ![](assets/test_pic2.png) 58 | ![](assets/testPic3.png) 59 | ### Submitting solution pics: 60 | ![](assets/submit_pic1.png) 61 | ![](assets/submit_pic2.png) 62 | 63 | ### Contact information: 64 | Please conact me if you have any query regarding the usage or if you want to contribute to the code. 65 | **Email**: parikshithraju8@gmail.com -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/show_pic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/show_pic1.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/show_pic2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/show_pic2.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/show_pic3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/show_pic3.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/show_pic5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/show_pic5.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/show_pic6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/show_pic6.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/show_pic7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/show_pic7.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/show_pic8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/show_pic8.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/submit_pic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/submit_pic1.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/submit_pic2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/submit_pic2.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/testPic3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/testPic3.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/test_pic2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/test_pic2.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/testing_pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/testing_pic.png -------------------------------------------------------------------------------- /Codechef_automation_bot/assets/tree_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/assets/tree_structure.png -------------------------------------------------------------------------------- /Codechef_automation_bot/chromedriver: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/Codechef_automation_bot/chromedriver -------------------------------------------------------------------------------- /Codechef_automation_bot/requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4==4.9.0 2 | certifi==2020.4.5.1 3 | chardet==3.0.4 4 | idna==2.9 5 | pycrypto==2.6.1 6 | requests==2.23.0 7 | selenium==3.141.0 8 | simple-crypt==4.1.7 9 | soupsieve==2.0 10 | urllib3==1.25.9 11 | -------------------------------------------------------------------------------- /Codechef_automation_bot/setup.py: -------------------------------------------------------------------------------- 1 | import json 2 | from getpass import getpass 3 | from selenium import webdriver 4 | from selenium.webdriver.chrome.options import Options 5 | from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException 6 | import re 7 | import os 8 | import time 9 | from bs4 import BeautifulSoup 10 | import requests 11 | from shutil import copyfile 12 | import pickle 13 | from simplecrypt import encrypt 14 | 15 | origin_path = os.getcwd() 16 | 17 | basic_details = dict() 18 | print('{:🤝^95}'.format(' Welcome to codechef contest setup bot!!')) 19 | while 1: 20 | path = input('Enter the path in which you want to create the contest:') 21 | if not path.startswith('/'): 22 | print('Should put the absosute path of the directory') 23 | else: 24 | break 25 | 26 | print('{:^150}'.format('Make sure you give the correct username and password because you won\'t get an error even if ' 27 | 'you didn\'t !!!')) 28 | 29 | uname = input('Enter your codechef username:') 30 | passwd = getpass('Enter your codechef password:') 31 | 32 | basic_details['user_name'] = uname 33 | 34 | basic_details['path'] = os.getcwd() 35 | 36 | encryptedPass = encrypt('password', passwd) 37 | 38 | basic_details['password'] = encryptedPass # FIXME:hash the password before saving it 39 | 40 | months = ['JAN', 'FEB', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUG', 'SEPT', 'OCT', 'DEC'] 41 | 42 | 43 | def unmark(content): 44 | bs = "" 45 | for i in content.text[content.text.find('\n', 1):].split('\n'): 46 | if i: 47 | i = i.replace('$', '') 48 | i = i.replace('\le', '<=') 49 | i = i.replace('\lt', '<') 50 | i = i.replace('*', '') 51 | i = i.replace('###', '\n') 52 | i = i.replace('\ldots', '...') 53 | i = i.replace('`', '') 54 | bs += (i.strip(' ') + '\n') 55 | return bs 56 | 57 | 58 | def CreateDict(contests, laddress): 59 | # TODO: need to correct what year is shown in the name of the file. 60 | for month in months: 61 | if laddress and month in laddress: 62 | contests[month + ' long challange'] = {'linkAddr': laddress} 63 | break 64 | else: 65 | if laddress and 'COOK' in laddress: 66 | monthIn = int(re.findall(r'[0-9]+', laddress)[0]) 67 | month = months[(monthIn - 5) % 12 - 1] 68 | contests[month + ' cook off'] = {'linkAddr': laddress} 69 | 70 | elif laddress and 'LTIME' in laddress: 71 | monthIn = int(re.findall(r'[0-9]+', laddress)[0]) 72 | month = months[(monthIn - 7) % 12 - 1] 73 | contests[month + ' lunch time'] = {'linkAddr': laddress} 74 | return (contests) 75 | 76 | 77 | # FIXME: fix the timing of the searching of elements gets real anoying when we aren't noticing 78 | def getContent(probName): 79 | url = 'https://www.codechef.com/' + probDict[probName]['link'] 80 | probPage = requests.get(url) 81 | probsoup = BeautifulSoup(probPage.text, features="html.parser") 82 | time.sleep(2) 83 | cont = probsoup.select('#problem-page > div > div > div.primary-colum-width-left')[0] 84 | problem = cont.select('div')[0] 85 | content = problem.select('div')[1] 86 | content = unmark(content) 87 | return (content) 88 | 89 | 90 | def getInputCases(content): 91 | inpStr = "" 92 | for i in content[content.find(' Example Input'):content.find(' Example Output')].split('\n')[1:]: 93 | inpStr += i 94 | inpStr += '\n' 95 | inpStr = inpStr.strip() 96 | return (inpStr) 97 | 98 | 99 | def getOutputCases(content): 100 | outStr = "" 101 | if content.find(' Explanation') != -1: 102 | for i in content[content.find(' Example Output'):content.find(' Explanation')].split('\n')[1:]: 103 | outStr += i 104 | outStr += '\n' 105 | else: 106 | for i in content[content.find(' Example Output'):content.find('All')].split('\n')[1:]: 107 | outStr += i 108 | outStr += '\n' 109 | outStr = outStr.strip() 110 | return (outStr) 111 | 112 | 113 | chromeOptions = Options() 114 | chromeOptions.add_argument('--headless') 115 | 116 | driver = webdriver.Chrome('./chromedriver', options=chromeOptions) 117 | 118 | print('1).Do you want to use our ui or') 119 | print('2).Will you put the link of the contest') 120 | c = int(input('Enter your choice:')) 121 | if c == 2: 122 | TargetPath = input('Enter URL of the contest:') 123 | contests = {} 124 | contests = CreateDict(contests, TargetPath) 125 | ch = 1 126 | else: 127 | driver.get('https://www.codechef.com') 128 | time.sleep(2) 129 | links = driver.find_elements_by_tag_name('a') 130 | contests = dict() 131 | for link in links: 132 | try: 133 | laddress = link.get_attribute('href') 134 | except StaleElementReferenceException: 135 | continue 136 | contests.update(CreateDict(contests, laddress)) 137 | while 1: 138 | i = 1 139 | for contest in contests.keys(): 140 | print(str(i) + ').' + contest) 141 | i += 1 142 | print(str(i) + ').Exit') 143 | ch = int(input('Enter your choice to participate ( ex:1 for 1st choice):')) 144 | try: 145 | driver.get((list(contests.values())[ch - 1]['linkAddr'])) 146 | except IndexError: 147 | break 148 | print('Invalid choice') 149 | while 1: 150 | try: 151 | details = driver.find_element_by_xpath('//*[@id="rules"]/div/div/div/ul[1]') 152 | break 153 | except NoSuchElementException: 154 | pass 155 | print('------------------------------------------------') 156 | print('Timing details:') 157 | print(details.text[:details.text.find('Check')]) 158 | print('------------------------------------------------') 159 | announcments = driver.find_element_by_xpath('//*[@id="announcements"]') 160 | print(announcments.text) 161 | print('------------------------------------------------') 162 | print('In which division would you like to particpate:\n') 163 | print('1).Division A\n2).Division B\n3).Do you want to see the contests menu again\n') 164 | divCh = int(input('Enter your choice:')) 165 | if divCh != 3: 166 | DestUrl = (list(contests.values())[ch - 1]['linkAddr']) 167 | if DestUrl.find('?') != -1: 168 | TargetPath = DestUrl[:DestUrl.find('?')] + ('A' if divCh == 1 else 'B') 169 | else: 170 | TargetPath = DestUrl + ('A' if divCh == 1 else 'B') 171 | break 172 | else: 173 | print('+++++++++++++++++++++++++++++++++++++++++++++') 174 | 175 | contCode = TargetPath.split('/')[-1] 176 | basic_details['contest-code'] = contCode 177 | 178 | res = requests.get(TargetPath) 179 | soup = BeautifulSoup(res.text, features="html.parser") 180 | 181 | probDict = dict() 182 | table = soup.select('#primary-content > div.content-spacer > div > div > table')[0] 183 | tbody = table.select('tbody')[0] 184 | trows = tbody.select('tr') 185 | for row in trows: 186 | eles = row.select('td') 187 | name = eles[0].text 188 | code = eles[1].text 189 | subs = eles[2].text 190 | acc = eles[3].text 191 | contCode = contCode.split('?')[0] 192 | link = contCode + '/problems/' + code 193 | probDict[name.strip()] = {'link': link.strip(), 'subs': subs.strip(), 'code': code.strip(), 'acc': acc.strip()} 194 | 195 | contName = list(contests.keys())[ch - 1].replace(' ', '_') 196 | os.chdir(path) 197 | # origin_path = os.getcwd() 198 | try: 199 | os.mkdir(contName) 200 | except FileExistsError: 201 | pass 202 | os.chdir(contName) 203 | for problem in probDict.items(): 204 | rPname = problem[0] 205 | pName = problem[0].replace(' ', '_') 206 | print('Creating ' + pName + ' Directory') 207 | try: 208 | os.mkdir(pName) 209 | except FileExistsError: 210 | pass 211 | os.chdir(pName) 212 | if rPname: 213 | content = getContent(rPname) 214 | inpStr = getInputCases(content) 215 | outStr = getOutputCases(content) 216 | print('writing statment.txt in ' + pName) 217 | with open('statment.txt', 'w') as f: 218 | f.write(content) 219 | f.close() 220 | print('writing input.dat in ' + pName) 221 | with open('given_input.dat', 'w') as f: 222 | f.write(inpStr) 223 | f.close() 224 | print('writing output.dat in ' + pName) 225 | with open('giver_output.dat', 'w') as f: 226 | f.write(outStr) 227 | f.close() 228 | print('Creating sol.cpp in ' + pName) 229 | copyfile(origin_path + '/template.cpp', './sol.cpp') 230 | # with open('sol.cpp', 'w') as f: 231 | # f.close() 232 | print('copying test.py file in ' + pName) 233 | copyfile(origin_path + '/test.py', './test.py') 234 | print('copying submit.py file in ' + pName) 235 | copyfile(origin_path + '/submit.py', './submit.py') 236 | print('Creating a problem.json file') 237 | with open('problem.json', 'w') as f: 238 | json.dump(problem[1], f) 239 | print('----------------------------------------------') 240 | 241 | os.chdir('..') 242 | os.chdir(origin_path) 243 | print('Successfuly created a contest for you !!!!') 244 | 245 | # with open(path + '/' + contName + '/basic_details.json', 'w') as file: 246 | # json.dump(basic_details, file) 247 | 248 | with open(path + '/' + contName + '/basic_details.json', 'wb') as f: 249 | pickle.dump(basic_details, f) 250 | -------------------------------------------------------------------------------- /Codechef_automation_bot/submit.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.chrome.options import Options 3 | from selenium.common.exceptions import NoSuchElementException 4 | import os 5 | import time 6 | import json 7 | import pickle 8 | from simplecrypt import decrypt 9 | import itertools 10 | import threading 11 | import time 12 | import sys 13 | 14 | done = False 15 | 16 | 17 | # here is the animation 18 | def animate(): 19 | for c in itertools.cycle(['|', '/', '-', '\\']): 20 | if done: 21 | break 22 | sys.stdout.write('\rSubmiting your code to the online judge(It takes time please be patient):' + c) 23 | sys.stdout.flush() 24 | time.sleep(0.1) 25 | print('\n') 26 | 27 | 28 | t = threading.Thread(target=animate) 29 | t.start() 30 | 31 | basic_details = {} 32 | with open('../basic_details.json', 'rb') as f: 33 | basic_details = pickle.load(f) 34 | 35 | chromeOptions = Options() 36 | chromeOptions.add_argument('--headless') 37 | driver = webdriver.Chrome(basic_details['path'] + '/chromedriver', options=chromeOptions) 38 | 39 | driver.get('https://www.codechef.com') 40 | 41 | time.sleep(3) 42 | # TODO : Ask for username and password from user and tell the user that we will logout of existing places 43 | 44 | password = decrypt('password', basic_details['password']).decode('utf8') 45 | 46 | # Logging in 47 | uname_sel = driver.find_element_by_css_selector('#edit-name') 48 | pass_sel = driver.find_element_by_css_selector('#edit-pass') 49 | sub_sel = driver.find_element_by_css_selector('#edit-submit') 50 | uname_sel.send_keys(basic_details['user_name']) 51 | pass_sel.send_keys(password) 52 | sub_sel.click() 53 | try: 54 | time.sleep(5) 55 | limit_page = driver.find_element_by_css_selector('#session-limit-page > div > div > div') 56 | checks = limit_page.find_elements_by_tag_name('input') 57 | time.sleep(5) 58 | for i in checks[:-1]: 59 | i.click() 60 | sub = driver.find_element_by_css_selector('#edit-submit') 61 | sub.click() 62 | except NoSuchElementException: 63 | pass 64 | 65 | with open('problem.json', 'r') as f: 66 | prob_details = json.load(f) 67 | # TODO: Make a json from the setup.py file to get the link to submit page of the problem 68 | page_link = 'https://www.codechef.com/submit/' + prob_details['code'] 69 | pwd = os.getcwd() 70 | driver.get(page_link) 71 | 72 | # File uploading and selecting the language and clicking 73 | while 1: 74 | try: 75 | file_sel = driver.find_element_by_css_selector('#edit-sourcefile') 76 | file_sel.send_keys(pwd + '/sol.cpp') 77 | lang_sel = driver.find_element_by_css_selector('#edit-language') 78 | langs = lang_sel.find_elements_by_tag_name('option') 79 | for i in langs: 80 | if 'C++14(gcc 6.3)' in i.text: 81 | i.click() 82 | submit_file_sel = driver.find_element_by_css_selector('#edit-submit-1') 83 | submit_file_sel.click() 84 | break 85 | except NoSuchElementException: 86 | pass 87 | # End file upload and submit 88 | 89 | 90 | # Getting information from the result page 91 | while 1: 92 | try: 93 | overall_res = driver.find_element_by_css_selector('#display_result > center > strong') 94 | sub_table = driver.find_element_by_css_selector('#status_table > table > tbody') 95 | status = sub_table.find_elements_by_tag_name('tr') 96 | break 97 | except NoSuchElementException: 98 | pass 99 | # End of getting info from result page 100 | 101 | 102 | # putting info result info into suitable containers 103 | sub_tasks = [] 104 | subtask_scores = [] 105 | total_score = status[-1].text 106 | for i in status[1:-1]: 107 | if 'Subtask' in i.text: 108 | sub_tasks.append('*') 109 | subtask_scores.append(i.text) 110 | else: 111 | sub_tasks.append(i.text) 112 | 113 | # Printing the result in appropriate from 114 | 115 | done=True 116 | print('\n') 117 | if 'Correct Answer' != overall_res.text: 118 | print('{:😥^35}'.format(overall_res.text)) 119 | else: 120 | print('{:👏^35}'.format(overall_res.text)) 121 | cnt = 0 122 | print('\n{:^20}{:^20}{:^20}'.format('Sub-Task', 'Task #', 'Result (time)')) 123 | for i in sub_tasks: 124 | if i == '*': 125 | print('\n{:*^60}'.format(subtask_scores[cnt])) 126 | cnt += 1 127 | else: 128 | l = i.split(' ') 129 | print('\n{:^20}{:^20}{:^20}'.format(l[0], l[1], l[2].split('\n')[0] + ' ' + l[2].split('\n')[1])) 130 | print('\n{:^60}'.format(total_score)) 131 | 132 | # End of displaying the result 133 | -------------------------------------------------------------------------------- /Codechef_automation_bot/template.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | //Write your code here 10 | } 11 | } -------------------------------------------------------------------------------- /Codechef_automation_bot/test.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | comp_string = subprocess.getoutput('g++ sol.cpp') 4 | 5 | rtime_errs = "" 6 | if not comp_string: 7 | rtime_errs = subprocess.getoutput('./a.out< given_input.dat >yourOut.dat') 8 | else: 9 | print('comp:' + comp_string) 10 | exit() 11 | if rtime_errs: 12 | print(rtime_errs) 13 | exit() 14 | your = open('yourOut.dat', 'r') 15 | their = open('giver_output.dat', 'r') 16 | yout = list(map(str.strip, your.readlines())) 17 | tout = list(map(str.strip, their.readlines())) 18 | ylen, tlen = len(yout), len(tout) 19 | 20 | if ylen == tlen: 21 | for i in range(0, tlen): 22 | if yout[i] != tout[i]: 23 | print('Outputs doesn\'t Match 😥 keep trying 💪 .To see your output see yourOut.dat file.') 24 | break 25 | else: 26 | print('Outputs Match Awesome 👏 👏 🎉 🎊 . To see your output see yourOut.dat file.') 27 | else: 28 | print('Output doesn\'t Match 😥 keep trying 💪 .To see your output see yourOut.dat file.') 29 | -------------------------------------------------------------------------------- /KS/1. fetch data.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/1. fetch data.PNG -------------------------------------------------------------------------------- /KS/1. fetch.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/1. fetch.PNG -------------------------------------------------------------------------------- /KS/MAIN APP/address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import pyap 4 | 5 | # below test_address, t3, test variable is a test case which can used in debugging otherwise it ain't used in our app 6 | test_address = """ 7 | David, 8 | 9 | We need a witness statement for one of our files. Please see below for 10 | the list of questions. 11 | 12 | Witness name: Salina Ramos 13 | Phone: (818) 723-6578 14 | 15 | 16 | Sincerely, 17 | 18 | Jackie Levine 19 | Assistant to Kyle K. Madison 20 | 21 | 22 | 23 | 11111 Santa Monica Blvd, Suite 100 24 | Los Angeles, CA 90025 25 | (310) 201-7676 (Office) 26 | (310) 744-0111 (Fax) 27 | 28 | The information in this e-mail (including attachments, if any) is 29 | considered confidential and is intended only for the recipient(s) listed 30 | above. Any review, use, disclosure, distribution or copying of this e-mail 31 | is prohibited except by or on behalf of the intended recipient. If you 32 | have received this email in error, 33 | """ 34 | test = ''' 35 | Hi David, 36 | 37 | Please send someone to sign: 38 | 39 | Maria Reyes 40 | Ph: 909-246-5391 (SPANISH) 41 | Address: 4138 Mission Blvd Space 58, Montclair, CA 91763 42 | DOL 01/08/2018 43 | 44 | Thank you 45 | 46 | 47 | ''' 48 | t2 = ''' 49 | Hello Team, 50 | 51 | We have a family that was involved in a MVA and needs to be contacted to set up an appointment for tomorrow, clients prefer at 11:00 a.m. 52 | 53 | Here is the contact person/client and location of sign-up, please note adult clients areSpanish speaking only: 54 | 55 | Jose A. Rios 56 | *400 Palm Avenue* 57 | *Watsonville, CA 95076* 58 | (831) 234-3634 59 | 60 | Date of Accident: 12/17/17 61 | 62 | Clients: 63 | 64 | 1. Juan R. Vega – driver 65 | 2. Jose A. Rios – passenger & vehicle owner 66 | 3. Enriqueta Rios – passenger & wife to Jose Rios 67 | 4. Elizabeth Rios – passenger & daughter to Jose Rios [she has down syndrome, Jose Rios will be her legal guardian and will answer questions on her behalf] 68 | 5. Roxanna Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 69 | 6. Iliana Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 70 | 71 | All adult clients will be at the above address, we are waiting to confirm if the father of both minors will be present, if not a separate meeting will be necessary. 72 | 73 | ''' 74 | t3 = ''' 75 | Jose A. Rios 76 | *400 Palm Avenue* 77 | *Watsonville, CA 95076* 78 | ''' 79 | def preprocess(arr_body): 80 | '''raw string can be of type 81 | '*Washington DC, 848101*' 82 | So it can't be fetched by the pyap module 83 | so refine the format of address 84 | ''' 85 | 86 | new_arr = [] 87 | for line in arr_body: 88 | line = line.replace('*', '') # replace '*' with '' 89 | new_arr.append(line) # add the refined line to the list 90 | return new_arr 91 | 92 | def fetch_address(arr_body): 93 | '''takes input list of body 94 | and extract address from it 95 | ''' 96 | msg_body = preprocess(arr_body) # refine the body 97 | msg_body = '\n'.join(msg_body) # make a string out of the list 98 | addresses = pyap.parse(msg_body, country='US') # selecting the country as 'US' parse the body and extract address 99 | location = [] # to include the address 100 | 101 | try: # if addresses contains any element 102 | for address in addresses: 103 | # shows found address 104 | location.append(address) # apppend the address 105 | # print address 106 | except: # if no elements simply pass 107 | pass 108 | return location 109 | 110 | #print(address.as_dict()) 111 | # print fetch_address(t3) 112 | -------------------------------------------------------------------------------- /KS/MAIN APP/address.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP/address.pyc -------------------------------------------------------------------------------- /KS/MAIN APP/check_date.py: -------------------------------------------------------------------------------- 1 | import pytz 2 | import date_extractor 3 | 4 | text = "need to get two signatures." 5 | dates = date_extractor.extract_dates(text) 6 | 7 | print (dates) 8 | 9 | -------------------------------------------------------------------------------- /KS/MAIN APP/dol_extractor.py: -------------------------------------------------------------------------------- 1 | import pytz 2 | import date_extractor 3 | 4 | def extract_dol(lines): 5 | '''take list as input 6 | break it into lines and 7 | extract date from each lines 8 | if present 9 | ''' 10 | 11 | dates_arr = [] 12 | for line in lines: 13 | dates = date_extractor.extract_dates(line) 14 | for date in dates: 15 | dates_arr.append(date.date()) 16 | 17 | return dates_arr 18 | 19 | # TEST CASE 20 | # text = "need to get two signatures.DoL: 9 feb 1986 with accident yesterday dOL: 19 feb, 2019" 21 | # for i in extract_dol(text): 22 | # print i 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /KS/MAIN APP/dol_extractor.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP/dol_extractor.pyc -------------------------------------------------------------------------------- /KS/MAIN APP/filters.py: -------------------------------------------------------------------------------- 1 | # unwanted words in subjects 2 | subject_items = [ 3 | 'URGENT', 4 | 'SIGN', 5 | 'UP', 6 | 'RETAINER', 7 | 'PICKUP', 8 | 'NEW', 9 | 'CASE', 10 | 'CLIENT', 11 | 'LEAD', 12 | ':', 13 | '-', 14 | 'RE', 15 | 'FWD', 16 | 'FW', 17 | 'SIGN-UP' 18 | 19 | ] 20 | 21 | # unwanted keywords in phone number 22 | phone_items = [ 23 | '(', 24 | ')', 25 | '-' 26 | ] 27 | 28 | # words to look for for signatures 29 | sign_items_pre = [ 30 | 'SIGNATURE', 31 | 'SIGN' 32 | ] 33 | 34 | # number of signatures possible 35 | sign_items_post = [ 36 | 'ONE', 37 | 'TWO', 38 | 'THREE', 39 | 'FOUR', 40 | 'FIVE', 41 | 'SIX', 42 | 'SEVEN', 43 | 'EIGHT', 44 | 'NINE', 45 | 'TEN', 46 | 'ELEVEN', 47 | 'TWELVE', 48 | '1', 49 | '2', 50 | '3', 51 | '4', 52 | '5', 53 | '6', 54 | '7', 55 | '8', 56 | '9', 57 | '10', 58 | '11', 59 | '12' 60 | ] -------------------------------------------------------------------------------- /KS/MAIN APP/filters.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP/filters.pyc -------------------------------------------------------------------------------- /KS/MAIN APP/info.py: -------------------------------------------------------------------------------- 1 | us_states = ['WA', 'Washington', 'WI', 'Wisconsin', 2 | 'WV', 'West Virginia', 'FL', 3 | 'Florida', 'WY', 'Wyoming', 'NH', 4 | 'New Hampshire', 'NJ', 'New Jersey', 5 | 'NM', 'New Mexico', 'NA', 6 | 'NC', 'North Carolina', 7 | 'ND', 'North Dakota', 'NE', 8 | 'Nebraska', 'NY', 'New York', 'RI', 9 | 'Rhode Island', 'NV', 'Nevada', 10 | 'GU', 'Guam', 'CO', 'Colorado', 11 | 'CA', 'California', 'GA', 'Georgia', 12 | 'CT', 'Connecticut', 'OK', 13 | 'Oklahoma', 'OH', 'Ohio', 'KS', 14 | 'Kansas', 'SC', 'South Carolina', 15 | 'KY', 'Kentucky', 'OR', 'Oregon', 16 | 'SD', 'South Dakota', 'DE', 17 | 'Delaware', 'DC', 18 | 'District of Columbia', 'HI', 19 | 'Hawaii', 'PR', 'Puerto Rico', 'TX', 20 | 'Texas', 'LA', 'Louisiana', 'TN', 21 | 'Tennessee', 'PA', 'Pennsylvania', 22 | 'VA', 'Virginia', 'VI', 23 | 'Virgin Islands', 'AK', 'Alaska', 24 | 'AL', 'Alabama', 'AS', 25 | 'American Samoa', 'AR', 'Arkansas', 26 | 'VT', 'Vermont', 'IL', 'Illinois', 27 | 'IN', 'Indiana', 'IA', 'Iowa', 'AZ', 28 | 'Arizona', 'ID', 'Idaho', 'ME', 29 | 'Maine', 'MD', 'Maryland', 'MA', 30 | 'Massachusetts', 'UT', 'Utah', 'MO', 31 | 'Missouri', 'MN', 'Minnesota', 'MI', 32 | 'Michigan', 'MT', 'Montana', 'MP', 33 | 'Northern Mariana Islands', 'MS', 34 | 'Mississippi' 35 | ] 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /KS/MAIN APP/info.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP/info.pyc -------------------------------------------------------------------------------- /KS/MAIN APP/name.py: -------------------------------------------------------------------------------- 1 | import re 2 | import nltk 3 | from nltk.corpus import stopwords 4 | stop = stopwords.words('english') # to set the words selection as ENGLISH 5 | 6 | # below document AND check variables is a test case which can used in debugging otherwise it ain't used in our app 7 | document=""" 8 | David, 9 | 10 | I need this signed up ASAP in Santa Cruz. Brain injury. Wi 11 | 12 | Joshua Orosco 13 | Tel#: 831-201 7096 14 | 15 | Needs a call right now to schedule time and location 16 | 17 | Reza 18 | 19 | 20 | -- 21 | Reza Torkzadeh 22 | Office: 888.222.8286 23 | Mobile: 949.698.8087 24 | 25 | Please note: This message is being sent via mobile phone. Please excuse any informalities, brevity, spelling and grammatical errors. 26 | """ 27 | check = ['Annette Anderson,', 28 | 'The client is a referral from our chiro- she is there now about to have her', 29 | 'appointment. Please reach out in the next hour!', 'Respectfully,'] 30 | 31 | def extract_names(document): 32 | '''takes a string input and 33 | print a set of all the names present in it 34 | ''' 35 | document = '\n'.join(document) # create a string from the document list 36 | document = ' '.join([i for i in document.split() if i not in stop]) 37 | sentences = nltk.sent_tokenize(document) # tokenizing the document 38 | sentences = [nltk.word_tokenize(sent) for sent in sentences] # now word_tokenizing the sentences 39 | sentences = [nltk.pos_tag(sent) for sent in sentences] # pos_tagging the sentences 40 | names = [] # create a list to contain names 41 | for tagged_sentence in sentences: 42 | for chunk in nltk.ne_chunk(tagged_sentence): 43 | if type(chunk) == nltk.tree.Tree: # check the chunk type 44 | if chunk.label() == 'PERSON': # if the chunk type is PERSON 45 | names.append(' '.join([c[0] for c in chunk])) # add such names or chunks 46 | 47 | 48 | names_unique=set(names) # make sure there is unique elements 49 | # print(names_unique) 50 | my_list = list(name.upper() for name in names_unique) # now create a list from the set names_unique 51 | return my_list 52 | 53 | #print extract_names(check) 54 | -------------------------------------------------------------------------------- /KS/MAIN APP/name.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP/name.pyc -------------------------------------------------------------------------------- /KS/MAIN APP/new_app.py: -------------------------------------------------------------------------------- 1 | # Reading inbox emails from CLI. 2 | # !/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | 9 | from info import us_states as states 10 | from address import fetch_address 11 | from name import extract_names 12 | from remove_sig import remove_signature 13 | from filters import (subject_items, phone_items, 14 | sign_items_post, sign_items_pre 15 | ) 16 | from stopwords_filter import process_names 17 | from dol_extractor import extract_dol 18 | 19 | # some constant datas to initialize with 20 | imaplib._MAXLINE = 400000 21 | 22 | ORG_EMAIL = "@gmail.com" 23 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 24 | FROM_PWD = getpass.getpass() 25 | SMTP_SERVER = "imap.gmail.com" # varies depending on the imap server 26 | SMTP_PORT = 993 27 | 28 | 29 | i = 0 # a counter to to move to next or previous mail 30 | body_fetched = [] # to contain all the lines which has been printed already 31 | 32 | 33 | def main(): 34 | ''' connect with the server 35 | fetch the mails and do the preprocessing 36 | ''' 37 | global i, body_fetched, email_message 38 | clear() # to clear the screen before fetching the mails 39 | # login 40 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) # connect with the server 41 | mail.login(FROM_EMAIL, FROM_PWD) # loggin in 42 | mail.list() # get a list of mails 43 | mail.select('inbox') # getting from the INBOX 44 | inp = 'n' # an inital counter for the first mail 45 | 46 | # start fetching mails one by one 47 | while (inp != 'q'): 48 | print('Fetching mails. Please wait...') 49 | if inp == 'n': # fetch next mail 50 | i += 1 51 | elif inp == 'p' and i != 1: # fetch previous mail, making sure it's not the first mail already 52 | i -= 1 53 | else: # in case user gives some invalid input 54 | print('Please enter valid input.') 55 | 56 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 57 | latest_email_uid = data[0].split()[-i] # fetch list of mails id 58 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') # iterate through the email and fetch the email using RFC822 protocol 59 | raw_email = data[0][1] # to get raw mails from the data fetched 60 | email_message = email.message_from_string(raw_email) # convert it as a string 61 | 62 | clear() # clear screen and print mail 63 | print 'To:', email_message['To'] # print TO of the mail 64 | print 'Sent from:', email_message['From'] # print FROM of the mail 65 | print 'Date:', email_message['Date'] # print DATE of the mail 66 | 67 | # preprocess the subject to remove unwanted words 68 | subject = [p.upper() for p in email_message['Subject'].split()] # break subject into list 69 | for item in subject_items: # iterate n delete the unwanted items 70 | if item in subject: 71 | try: 72 | subject.remove(item) 73 | except: 74 | pass 75 | 76 | subject = ' '.join(subject) 77 | print 'Subject:', subject # print SUBJECT of the mail 78 | 79 | print '\n' 80 | maintype = email_message.get_content_maintype() # check the type of mail 81 | 82 | if maintype == 'multipart': # get the body of the mail if type is 'multipart' 83 | body = email_message.get_payload()[0].get_payload() # to get the plain text only 84 | elif maintype == 'text': # get the body if the mail if type is 'text' 85 | body = email_message.get_payload()[0] 86 | 87 | 88 | body = remove_signature(body) # preprocessing the body to remove signature 89 | 90 | body_fetched = [] # to keep the track of things we gonna extract from the body like DOL, phone no. 91 | dols_in = extract_dol_in(body) 92 | dols = extract_dol(dols_in) # extract DOL 93 | phone_num = get_phoneNumber(body) # extract phone no 94 | 95 | # removing unwanted keywords from phone no 96 | phone_no = list(phone_num) 97 | for item in phone_items: 98 | if item in phone_no: 99 | phone_no = list(filter(lambda a: a != item, phone_no)) 100 | 101 | phone_no = ''.join(phone_no) 102 | 103 | # adding the items in the body_fetched list 104 | body_fetched.extend(phone_num.split('\n')) 105 | 106 | 107 | print 'Phone Number: ', phone_no 108 | print 'DOL: ' 109 | for dol in dols: # print the DOLs 110 | print str(dol) 111 | 112 | print '\n' 113 | 114 | remaining_body_location = remaining_msg(body.split('\n'), body_fetched) # get the body after removing what we extracted 115 | 116 | location = fetch_address(remaining_body_location) # extract location 117 | 118 | if len(location) != 0: # if some location is extracted by ML method 119 | for address in location: 120 | body_fetched.append(str(address)) # add the location to the body_fetched list 121 | print 'Address: ', address # print address 122 | else: # if no location is extracted then try the brute force 123 | loc = location_fetch(remaining_body_location) # extract location 124 | body_fetched.append(str(loc)) # add it to the list 125 | loc = loc.split() # create a list breaking the address line in words 126 | new_locs = [] # create a list to add the words in location 127 | for lo in loc: # if the location line starts with 'ADDRESS' then remove it and add the remaining words in new_locs list 128 | if 'ADDRESS' not in lo.upper(): 129 | new_locs.append(lo) 130 | 131 | print 'Address: ', ' '.join(new_locs) # print the location as a string forming from the new_locs list 132 | 133 | remaining_body_name = remaining_msg(remaining_body_location, body_fetched) # get the body after removing what we extracted 134 | 135 | # filtering out no of sign/cases 136 | req_line = '' 137 | for item in sign_items_pre: 138 | for part in remaining_body_name: 139 | if item in part.upper(): 140 | req_line = part 141 | break 142 | 143 | req_item = '' 144 | for item in sign_items_post: 145 | if item in req_line.split(): 146 | req_item = item 147 | break 148 | 149 | print 'NO OF CASES/SIGNS: ', req_item 150 | print '\n' 151 | try: 152 | remaining_body_name = process_names(remaining_body_name) # remove the stopwords 153 | except: 154 | pass 155 | 156 | names = extract_names(remaining_body_name) # extract the names from the remaining body 157 | 158 | print '\n' 159 | 160 | 161 | print 'Name: ', 162 | if len(remaining_body_name) != 0: # if there are names extracted 163 | if 'DAVID' in remaining_body_name[0].upper(): # if first line contains DAVID ignore it. 164 | names.remove('DAVID') 165 | 166 | for j in range(len(names)): # print names 167 | print names[j] 168 | 169 | welcome() # print the welcome message 170 | inp = raw_input('>> Enter your choice: ').lower() # take the input for next/previous mails 171 | 172 | 173 | def extract_dol_in(body): 174 | '''splitting the message into lines 175 | and extracting the lines with DOL in it 176 | ''' 177 | 178 | dol_matches = ['DOL', 'DATE OF LOSS', 'DATE OF ACCIDENT'] # creating the possible ways of writing DOLs 179 | body = body.split('\n') # create a list based on the every next line 180 | dol_arr = [] # create a list to add the DOL if there is any in the list 181 | for line in body: 182 | for dol in dol_matches: 183 | if dol in line.upper(): # if any DOL or similar words are there in body then add it to the list 184 | dol_arr.append(line) 185 | return dol_arr 186 | 187 | 188 | # extract phone no using regex 189 | def get_phoneNumber(text): 190 | ''' Matches 3334445555, 333.444.5555, 333-444-5555, 191 | 333 444 5555, (333) 444 5555 and all combinations thereof, 192 | like 333 4445555, (333)4445555 or 333444-5555. 193 | Does not match international notation +13334445555, 194 | but matches domestic part in +1 333 4445555. 195 | using regex for extracting phone numbers 196 | then pass that compiled regex to get_phoneNumbers 197 | function and returns a string of phone numbers 198 | present in the text 199 | ''' 200 | 201 | phone_number = "" 202 | regex = re.compile(r"\(?\b[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}\b") # regex to match the pattern of phone no 203 | for phoneNumber in get_phoneNumbers(text, regex): # get a list of all phone no present present using function get_phoneNumbers 204 | phone_number = phone_number + phoneNumber + "\n" # create a string of phone no from the list returned 205 | return phone_number 206 | 207 | 208 | def get_phoneNumbers(s, regex): 209 | ''' returns all the phone numbers present 210 | in the input string 211 | ''' 212 | return (phoneNumber for phoneNumber in re.findall(regex, s)) # using the regex provided in function get_phoneNumber extract all phone no 213 | 214 | 215 | def remaining_msg(msg, fetched): 216 | '''to return a list of the message 217 | lines that hasn't been printed yet 218 | msg - list that is our mail body 219 | fetched - list that has been fetched and which needs 220 | to be removed from msg list 221 | 222 | ---- LOOP 1 description ---- 223 | ex- suppose we fetched 'Ram' from 'Ram is going to school'. 224 | So 'Ram'(element in fetched list) is a small part of 'Ram is going to school'(element in msg list). 225 | Hence fetched list element is smaller than or just a small part of msg list elements. 226 | Hence LOOP 1 checks for every such element in fetched list and helps to remove it from msg list 227 | 228 | ---- LOOP 2 description ---- 229 | ex - Suppose we fetched "3055 Wilshire Blvd., 12th Floor Los Angeles, CA 90010" from 230 | msg list "3055 Wilshire Blvd., 12th Floor" , "Los Angeles, CA 90010" 231 | Clearly fetched element is combination of two elements of msg list and hence bigger than 232 | both the elements so LOOP 2 searches for msg list elements(smaller) from the fethced list 233 | elements(bigger) and helps to remove it. 234 | ''' 235 | 236 | remains = [] # to contain the lines that need to be removed 237 | 238 | try: 239 | msg = [x.strip() for x in msg] # to remove the whitespaces from msg list 240 | fetched = [x.strip() for x in fetched] # to remove the whitespaces from fetched list 241 | msg = list(filter(lambda a: a != '', msg)) # to filter out '' kinda strings remained in msg list 242 | fetched = list(filter(lambda a: a != '', fetched)) # to filter out '' kinda strings remained in fetched list 243 | except: # if there is no whitespaces 244 | msg = [str(x) for x in msg] # first convert the raw msg list elements as string 245 | fetched = [str(x) for x in fetched] # convert the raw fetched list elements as string 246 | msg = list(filter(lambda a: a != '\r', msg)) # filter out '\r' kinda elements in msg list 247 | fetched = list(filter(lambda a: a != '\r', fetched)) # filter out '\r' kinda elements in msg list 248 | 249 | for fline in fetched: # check above for LOOP 1 description 250 | for line in msg: 251 | try: 252 | if line.find(fline) != -1: # if msg list contains any fetched list elements 253 | remains.append(line) # add it to the remains list 254 | break 255 | except: # if not contains then simply continue the loop 256 | pass 257 | 258 | for line in msg: # check above for LOOP 2 description 259 | for fline in fetched: 260 | try: 261 | if fline.find(line) != -1: # if fetched list contains any msg list elements 262 | remains.append(line) # add it to the remains list 263 | break 264 | except: # otherwise continue 265 | pass 266 | 267 | #print remains 268 | #print '\n', msg 269 | 270 | for line in remains: 271 | try: 272 | msg.remove(line) # now delete all the elements that we added in remains element 273 | except: 274 | pass # otherwise simply continue the loop 275 | return msg 276 | 277 | 278 | def location_fetch(msg): 279 | ''' the location ends with either state name or PIN 280 | using that this function checks for the words in each line 281 | if it contains the state then it will return the line 282 | ''' 283 | locs = [] # to add location if there is any 284 | for line in msg: 285 | linen = line.upper() 286 | if linen.find('ADDRESS') != -1: # check the line if it starts with 'ADDRESS' ex- 'ADDRESS: Los Angeles, CA 90010' 287 | locs.append(line) # include the line 288 | break 289 | for line in msg: 290 | words = line.split() # divide the msg lines into words 291 | for word in words: 292 | if word in states: # check if the words contains any US states name which is present in info.py file 293 | locs.append(line) # add the line 294 | return ' '.join(locs) # return the line as string 295 | 296 | 297 | def clear(): 298 | os.system('cls' if os.name == 'nt' else 'clear') # to refresh the screen i.e makes the screen blank 299 | 300 | 301 | def welcome(): 302 | '''shows the navigation menu for the tool''' 303 | print '\n' 304 | print '>> Enter \'n\' to check NEXT mail' 305 | print '>> Enter \'p\' to check PREVIOUS mail' 306 | print '>> Enter \'q\' to QUIT' 307 | 308 | 309 | if __name__ == '__main__': 310 | main() # run the file 311 | -------------------------------------------------------------------------------- /KS/MAIN APP/remove_sig.py: -------------------------------------------------------------------------------- 1 | import talon 2 | from talon import signature as sig 3 | from talon.signature.bruteforce import extract_signature 4 | # don't forget to init the library first 5 | # it loads machine learning classifiers 6 | talon.init() 7 | 8 | # text1, text2, text3 are test cases which can used in debugging otherwise they ain't use in our app 9 | text1 = '''(818) 212-8948 10 | DOL: 10/20/2017 & DOL: 6/2017 11 | 10906 Woodley Ave Granada Hills CA 12 | Client has two cases to sign 13 | 14 | -- 15 | Leslie Garcia, Intake Coordinator 16 | Akiva Niamehr LLP 17 | 10900 Wilshire Blvd. Ste. 930 | Los Angeles, CA 90024 18 | P: 424.653.1093 | F: 310.882.5444 19 | E: leslie@anattorneys.com 20 | ''' 21 | text3 = ''' 22 | Hi David, 23 | 24 | 25 | 26 | We need a witness statement for one of our files. Please see below for 27 | 28 | the list of questions. 29 | 30 | 31 | 32 | Witness name: Salina Ramos 33 | 34 | Phone: (818) 723-6578 35 | 36 | 37 | 38 | 39 | -- 40 | Abhinav Anand, 41 | +91 8461077468 42 | ABV-IIITM, GWALIOR, MP, 474015 43 | ''' 44 | text2 = """Annette Anderson, 45 | 11833 Spring Laurel DR 46 | Charlotte, NC 28215 47 | 704-724-4697 48 | 49 | Client is a referral from our chiro- she is there now about to have her appointment. Please reach out in the next hour! 50 | 51 | Respectfully, 52 | 53 | Lacie N. Johnson 54 | Intake Paralegal 55 | Law Offices of Shane Smith, PC 56 | 263 Hwy 74 N 57 | Peachtree City, GA 30269 58 | 59 | 770.487.8999 ext. 42 60 | 770.631.7667 fax 61 | """ 62 | 63 | def remove_signature(message): 64 | '''takes the message as string 65 | and returns a string removing signature 66 | ''' 67 | msge = message.split('\n') # break the message in line 68 | try: 69 | msg = [x.rstrip() for x in msge] # remove the white spaces 70 | except: 71 | pass # otherwise proceed 72 | message = '\n'.join(msg) # form a string from the msg list 73 | 74 | if '--' in msg: # method 1 by checking the occurence of '--' in msg list 75 | text, signature = extract_signature(message) # extract the filtered text and signature 76 | else: #METHOD 2 by using ML way 77 | text, signature = sig.extract(message, sender='john.doe@example.com') # extract the text and signature, the sender argument is necessary but any fake email id can be used 78 | 79 | return text 80 | 81 | 82 | # print remove_signature(text1) 83 | # print '\n\n' 84 | # print remove_signature(text3) 85 | -------------------------------------------------------------------------------- /KS/MAIN APP/remove_sig.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP/remove_sig.pyc -------------------------------------------------------------------------------- /KS/MAIN APP/stopwords_filter.py: -------------------------------------------------------------------------------- 1 | from nltk.corpus import stopwords 2 | from nltk.tokenize import word_tokenize 3 | 4 | stop_words = set(stopwords.words('english')) # setting the language 5 | 6 | 7 | def process_names(names): 8 | '''takes a input list 9 | and removes all the stopwords 10 | ''' 11 | 12 | line = ' '.join(names) # create a string out of the list 13 | word_tokens = word_tokenize(line) # tokenize the string 14 | 15 | filtered_sentence = [w for w in word_tokens if not w in stop_words] # filtering the words 16 | 17 | return filtered_sentence 18 | 19 | 20 | # ** Just a test case ** 21 | a = ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 22 | 'off', 'the', 'stop', 'words', 'filtration', '.'] 23 | 24 | -------------------------------------------------------------------------------- /KS/MAIN APP/stopwords_filter.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP/stopwords_filter.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after.zip -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import pyap 4 | 5 | # below test_address, t3, test variable is a test case which can used in debugging otherwise it ain't used in our app 6 | test_address = """ 7 | David, 8 | 9 | We need a witness statement for one of our files. Please see below for 10 | the list of questions. 11 | 12 | Witness name: Salina Ramos 13 | Phone: (818) 723-6578 14 | 15 | 16 | Sincerely, 17 | 18 | Jackie Levine 19 | Assistant to Kyle K. Madison 20 | 21 | 22 | 23 | 11111 Santa Monica Blvd, Suite 100 24 | Los Angeles, CA 90025 25 | (310) 201-7676 (Office) 26 | (310) 744-0111 (Fax) 27 | 28 | The information in this e-mail (including attachments, if any) is 29 | considered confidential and is intended only for the recipient(s) listed 30 | above. Any review, use, disclosure, distribution or copying of this e-mail 31 | is prohibited except by or on behalf of the intended recipient. If you 32 | have received this email in error, 33 | """ 34 | test = ''' 35 | Hi David, 36 | 37 | Please send someone to sign: 38 | 39 | Maria Reyes 40 | Ph: 909-246-5391 (SPANISH) 41 | Address: 4138 Mission Blvd Space 58, Montclair, CA 91763 42 | DOL 01/08/2018 43 | 44 | Thank you 45 | 46 | 47 | ''' 48 | t2 = ''' 49 | Hello Team, 50 | 51 | We have a family that was involved in a MVA and needs to be contacted to set up an appointment for tomorrow, clients prefer at 11:00 a.m. 52 | 53 | Here is the contact person/client and location of sign-up, please note adult clients areSpanish speaking only: 54 | 55 | Jose A. Rios 56 | *400 Palm Avenue* 57 | *Watsonville, CA 95076* 58 | (831) 234-3634 59 | 60 | Date of Accident: 12/17/17 61 | 62 | Clients: 63 | 64 | 1. Juan R. Vega – driver 65 | 2. Jose A. Rios – passenger & vehicle owner 66 | 3. Enriqueta Rios – passenger & wife to Jose Rios 67 | 4. Elizabeth Rios – passenger & daughter to Jose Rios [she has down syndrome, Jose Rios will be her legal guardian and will answer questions on her behalf] 68 | 5. Roxanna Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 69 | 6. Iliana Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 70 | 71 | All adult clients will be at the above address, we are waiting to confirm if the father of both minors will be present, if not a separate meeting will be necessary. 72 | 73 | ''' 74 | t3 = ''' 75 | Jose A. Rios 76 | *400 Palm Avenue* 77 | *Watsonville, CA 95076* 78 | ''' 79 | def preprocess(arr_body): 80 | '''raw string can be of type 81 | '*Washington DC, 848101*' 82 | So it can't be fetched by the pyap module 83 | so refine the format of address 84 | ''' 85 | 86 | new_arr = [] 87 | for line in arr_body: 88 | line = line.replace('*', '') # replace '*' with '' 89 | new_arr.append(line) # add the refined line to the list 90 | return new_arr 91 | 92 | def fetch_address(arr_body): 93 | '''takes input list of body 94 | and extract address from it 95 | ''' 96 | msg_body = preprocess(arr_body) # refine the body 97 | msg_body = '\n'.join(msg_body) # make a string out of the list 98 | addresses = pyap.parse(msg_body, country='US') # selecting the country as 'US' parse the body and extract address 99 | location = [] # to include the address 100 | 101 | try: # if addresses contains any element 102 | for address in addresses: 103 | # shows found address 104 | location.append(address) # apppend the address 105 | # print address 106 | except: # if no elements simply pass 107 | pass 108 | return location 109 | 110 | #print(address.as_dict()) 111 | # print fetch_address(t3) 112 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/address.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/MAIN APP/address.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/filters.py: -------------------------------------------------------------------------------- 1 | # unwanted words in subjects 2 | subject_items = [ 3 | 'URGENT', 4 | 'SIGN', 5 | 'UP', 6 | 'RETAINER', 7 | 'PICKUP', 8 | 'NEW', 9 | 'CASE', 10 | 'CLIENT', 11 | 'LEAD', 12 | ':', 13 | '-', 14 | 'RE', 15 | 'FWD', 16 | 'FW', 17 | 'SIGN-UP' 18 | 19 | ] 20 | 21 | # unwanted keywords in phone number 22 | phone_items = [ 23 | '(', 24 | ')', 25 | '-' 26 | ] 27 | 28 | # words to look for for signatures 29 | sign_items_pre = [ 30 | 'SIGNATURE', 31 | 'SIGN', 32 | 'SIGNATURES', 33 | 'SIGNS' 34 | ] 35 | 36 | # number of signatures possible 37 | sign_items_post = [ 38 | 'ONE', 39 | 'TWO', 40 | 'THREE', 41 | 'FOUR', 42 | 'FIVE', 43 | 'SIX', 44 | 'SEVEN', 45 | 'EIGHT', 46 | 'NINE', 47 | 'TEN', 48 | 'ELEVEN', 49 | 'TWELVE', 50 | '1', 51 | '2', 52 | '3', 53 | '4', 54 | '5', 55 | '6', 56 | '7', 57 | '8', 58 | '9', 59 | '10', 60 | '11', 61 | '12' 62 | ] 63 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/filters.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/MAIN APP/filters.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/info.py: -------------------------------------------------------------------------------- 1 | us_states = ['WA', 'Washington', 'WI', 'Wisconsin', 2 | 'WV', 'West Virginia', 'FL', 3 | 'Florida', 'WY', 'Wyoming', 'NH', 4 | 'New Hampshire', 'NJ', 'New Jersey', 5 | 'NM', 'New Mexico', 'NA', 6 | 'NC', 'North Carolina', 7 | 'ND', 'North Dakota', 'NE', 8 | 'Nebraska', 'NY', 'New York', 'RI', 9 | 'Rhode Island', 'NV', 'Nevada', 10 | 'GU', 'Guam', 'CO', 'Colorado', 11 | 'CA', 'California', 'GA', 'Georgia', 12 | 'CT', 'Connecticut', 'OK', 13 | 'Oklahoma', 'OH', 'Ohio', 'KS', 14 | 'Kansas', 'SC', 'South Carolina', 15 | 'KY', 'Kentucky', 'OR', 'Oregon', 16 | 'SD', 'South Dakota', 'DE', 17 | 'Delaware', 'DC', 18 | 'District of Columbia', 'HI', 19 | 'Hawaii', 'PR', 'Puerto Rico', 'TX', 20 | 'Texas', 'LA', 'Louisiana', 'TN', 21 | 'Tennessee', 'PA', 'Pennsylvania', 22 | 'VA', 'Virginia', 'VI', 23 | 'Virgin Islands', 'AK', 'Alaska', 24 | 'AL', 'Alabama', 'AS', 25 | 'American Samoa', 'AR', 'Arkansas', 26 | 'VT', 'Vermont', 'IL', 'Illinois', 27 | 'IN', 'Indiana', 'IA', 'Iowa', 'AZ', 28 | 'Arizona', 'ID', 'Idaho', 'ME', 29 | 'Maine', 'MD', 'Maryland', 'MA', 30 | 'Massachusetts', 'UT', 'Utah', 'MO', 31 | 'Missouri', 'MN', 'Minnesota', 'MI', 32 | 'Michigan', 'MT', 'Montana', 'MP', 33 | 'Northern Mariana Islands', 'MS', 34 | 'Mississippi' 35 | ] 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/info.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/MAIN APP/info.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/name.py: -------------------------------------------------------------------------------- 1 | import re 2 | import nltk 3 | from nltk.corpus import stopwords 4 | stop = stopwords.words('english') # to set the words selection as ENGLISH 5 | 6 | # below document AND check variables is a test case which can used in debugging otherwise it ain't used in our app 7 | document=""" 8 | David, 9 | 10 | I need this signed up ASAP in Santa Cruz. Brain injury. Wi 11 | 12 | Joshua Orosco 13 | Tel#: 831-201 7096 14 | 15 | Needs a call right now to schedule time and location 16 | 17 | Reza 18 | 19 | 20 | -- 21 | Reza Torkzadeh 22 | Office: 888.222.8286 23 | Mobile: 949.698.8087 24 | 25 | Please note: This message is being sent via mobile phone. Please excuse any informalities, brevity, spelling and grammatical errors. 26 | """ 27 | check = ['Annette Anderson,', 28 | 'The client is a referral from our chiro- she is there now about to have her', 29 | 'appointment. Please reach out in the next hour!', 'Respectfully,'] 30 | 31 | def extract_names(document): 32 | '''takes a string input and 33 | print a set of all the names present in it 34 | ''' 35 | document = '\n'.join(document) # create a string from the document list 36 | document = ' '.join([i for i in document.split() if i not in stop]) 37 | sentences = nltk.sent_tokenize(document) # tokenizing the document 38 | sentences = [nltk.word_tokenize(sent) for sent in sentences] # now word_tokenizing the sentences 39 | sentences = [nltk.pos_tag(sent) for sent in sentences] # pos_tagging the sentences 40 | names = [] # create a list to contain names 41 | for tagged_sentence in sentences: 42 | for chunk in nltk.ne_chunk(tagged_sentence): 43 | if type(chunk) == nltk.tree.Tree: # check the chunk type 44 | if chunk.label() == 'PERSON': # if the chunk type is PERSON 45 | names.append(' '.join([c[0] for c in chunk])) # add such names or chunks 46 | 47 | 48 | names_unique=set(names) # make sure there is unique elements 49 | # print(names_unique) 50 | my_list = list(name.upper() for name in names_unique) # now create a list from the set names_unique 51 | return my_list 52 | 53 | #print extract_names(check) 54 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/name.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/MAIN APP/name.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/name_extractor.py: -------------------------------------------------------------------------------- 1 | import nltk 2 | from nameparser.parser import HumanName 3 | 4 | # TEST CASE 5 | text = ['in the car version 2 and Abhinav Anand.', 6 | 'hi there John Vogue.','Regards,', 'Gaurav Sharma'] 7 | 8 | def get_human_names(text): 9 | ''' 10 | takes a string and 11 | returns a list of names present in it. 12 | ''' 13 | tokens = nltk.tokenize.word_tokenize(text) # tokenize 14 | pos = nltk.pos_tag(tokens) 15 | sentt = nltk.ne_chunk(pos, binary = False) # chunking 16 | person_list = [] 17 | person = [] 18 | name = "" 19 | for subtree in sentt.subtrees(filter=lambda t: t.label() == 'PERSON'): 20 | for leaf in subtree.leaves(): 21 | person.append(leaf[0]) 22 | if len(person) > 1: #avoid grabbing lone surnames 23 | for part in person: 24 | name += part + ' ' 25 | if name[:-1] not in person_list: 26 | person_list.append(name[:-1]) 27 | name = '' 28 | person = [] 29 | 30 | return (person_list) 31 | 32 | 33 | def crawl_names(lines): 34 | ''' 35 | takes a list of lines 36 | join the lines to form 37 | a string and extract the names 38 | using the get_human_names function 39 | above 40 | ''' 41 | text = '\n'.join(lines) 42 | names = get_human_names(text) 43 | return names 44 | 45 | 46 | print(crawl_names(text)) 47 | 48 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/name_extractor.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/MAIN APP/name_extractor.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/new_app.py: -------------------------------------------------------------------------------- 1 | # Reading inbox emails from CLI. 2 | # !/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | 9 | from info import us_states as states 10 | from address import fetch_address 11 | from remove_sig import remove_signature 12 | from filters import (subject_items, phone_items, 13 | sign_items_post, sign_items_pre 14 | ) 15 | from stopwords_filter import process_names 16 | from name_extractor import crawl_names 17 | 18 | # some constant datas to initialize with 19 | imaplib._MAXLINE = 400000 20 | 21 | ORG_EMAIL = "@gmail.com" 22 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 23 | FROM_PWD = getpass.getpass() 24 | SMTP_SERVER = "imap.gmail.com" # varies depending on the imap server 25 | SMTP_PORT = 993 26 | 27 | 28 | i = 0 # a counter to to move to next or previous mail 29 | body_fetched = [] # to contain all the lines which has been printed already 30 | 31 | 32 | def main(): 33 | ''' connect with the server 34 | fetch the mails and do the preprocessing 35 | ''' 36 | global i, body_fetched, email_message 37 | clear() # to clear the screen before fetching the mails 38 | # login 39 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) # connect with the server 40 | mail.login(FROM_EMAIL, FROM_PWD) # loggin in 41 | mail.list() # get a list of mails 42 | mail.select('inbox') # getting from the INBOX 43 | inp = 'n' # an inital counter for the first mail 44 | 45 | # start fetching mails one by one 46 | while (inp != 'q'): 47 | print('Fetching mails. Please wait...') 48 | if inp == 'n': # fetch next mail 49 | i += 1 50 | elif inp == 'p' and i != 1: # fetch previous mail, making sure it's not the first mail already 51 | i -= 1 52 | else: # in case user gives some invalid input 53 | print('Please enter valid input.') 54 | 55 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 56 | latest_email_uid = data[0].split()[-i] # fetch list of mails id 57 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') # iterate through the email and fetch the email using RFC822 protocol 58 | raw_email = data[0][1] # to get raw mails from the data fetched 59 | email_message = email.message_from_string(raw_email) # convert it as a string 60 | 61 | clear() # clear screen and print mail 62 | print 'To:', email_message['To'] # print TO of the mail 63 | print 'Sent from:', email_message['From'] # print FROM of the mail 64 | print 'Date:', email_message['Date'] # print DATE of the mail 65 | 66 | # preprocess the subject to remove unwanted words 67 | subject = [p.upper() for p in email_message['Subject'].split()] # break subject into list 68 | for item in subject_items: # iterate n delete the unwanted items 69 | if item in subject: 70 | try: 71 | subject.remove(item) 72 | except: 73 | pass 74 | 75 | subject = ' '.join(subject) 76 | print 'Subject:', subject # print SUBJECT of the mail 77 | 78 | print '\n' 79 | maintype = email_message.get_content_maintype() # check the type of mail 80 | 81 | if maintype == 'multipart': # get the body of the mail if type is 'multipart' 82 | body = email_message.get_payload()[0].get_payload() # to get the plain text only 83 | elif maintype == 'text': # get the body if the mail if type is 'text' 84 | body = email_message.get_payload()[0] 85 | 86 | 87 | body = remove_signature(body) # preprocessing the body to remove signature 88 | 89 | body_fetched = [] # to keep the track of things we gonna extract from the body like DOL, phone no. 90 | 91 | dols = extract_dol(body) # extract DOL 92 | phone_num = get_phoneNumber(body) # extract phone no 93 | 94 | # removing unwanted keywords from phone no 95 | phone_no = list(phone_num) 96 | for item in phone_items: 97 | if item in phone_no: 98 | phone_no = list(filter(lambda a: a != item, phone_no)) 99 | 100 | phone_no = ''.join(phone_no) 101 | 102 | # adding the two items in the body_fetched list 103 | body_fetched.extend(phone_num.split('\n')) 104 | body_fetched.extend(dols) 105 | 106 | print 'Phone Number: ', phone_no 107 | 108 | for dol in dols: # print the DOLs 109 | print str(dol) 110 | 111 | print '\n' 112 | 113 | remaining_body_location = remaining_msg(body.split('\n'), body_fetched) # get the body after removing what we extracted 114 | 115 | location = fetch_address(remaining_body_location) # extract location 116 | 117 | if len(location) != 0: # if some location is extracted by ML method 118 | for address in location: 119 | body_fetched.append(str(address)) # add the location to the body_fetched list 120 | print 'Address: ', address # print address 121 | else: # if no location is extracted then try the brute force 122 | loc = location_fetch(remaining_body_location) # extract location 123 | body_fetched.append(str(loc)) # add it to the list 124 | loc = loc.split() # create a list breaking the address line in words 125 | new_locs = [] # create a list to add the words in location 126 | for lo in loc: # if the location line starts with 'ADDRESS' then remove it and add the remaining words in new_locs list 127 | if 'ADDRESS' not in lo.upper(): 128 | new_locs.append(lo) 129 | 130 | print 'Address: ', ' '.join(new_locs) # print the location as a string forming from the new_locs list 131 | 132 | remaining_body_name = remaining_msg(remaining_body_location, body_fetched) # get the body after removing what we extracted 133 | 134 | # filtering out no of sign/cases 135 | req_line = '' 136 | for item in sign_items_pre: 137 | for part in remaining_body_name: 138 | if item in part.upper(): 139 | req_line = part 140 | break 141 | 142 | req_item = '' 143 | for item in sign_items_post: 144 | if item in req_line.upper().split(): 145 | req_item = item 146 | break 147 | 148 | print 'NO OF CASES/SIGNS: ', req_item 149 | print '\n' 150 | names = crawl_names(remaining_body_name) # extract the names from the remaining body 151 | names_copy = [x.upper() for x in names] # create a copy to iterate 152 | print '\n' 153 | 154 | 155 | print 'Name: ', 156 | if len(names_copy) != 0: # if there are names extracted 157 | if 'DAVID' in names_copy[0]: # if first line contains DAVID ignore it. 158 | names.remove(names[0]) 159 | unwanted_names = [] 160 | for neme in names: 161 | if 'REGARDS' in neme.upper(): 162 | unwanted_names.append(neme) 163 | if 'GAURAV' in neme.upper(): 164 | unwanted_names.append(neme) 165 | if 'SHARMA' in neme.upper(): 166 | unwanted_names.append(neme) 167 | 168 | for unwanted_name in unwanted_names: 169 | try: 170 | names.remove(neme) 171 | except: 172 | pass 173 | try: 174 | names = process_names(names) # remove the stopwords 175 | except: 176 | pass 177 | 178 | for j in range(len(names)): # print names 179 | print names[j] 180 | 181 | welcome() # print the welcome message 182 | inp = raw_input('>> Enter your choice: ').lower() # take the input for next/previous mails 183 | 184 | 185 | def extract_dol(body): 186 | '''splitting the message into lines 187 | and extracting the lines with DOL in it 188 | ''' 189 | 190 | dol_matches = ['DOL', 'DATE OF LOSS', 'DATE OF ACCIDENT'] # creating the possible ways of writing DOLs 191 | body = body.split('\n') # create a list based on the every next line 192 | dol_arr = [] # create a list to add the DOL if there is any in the list 193 | for line in body: 194 | for dol in dol_matches: 195 | if dol in line.upper(): # if any DOL or similar words are there in body then add it to the list 196 | dol_arr.append(line) 197 | return dol_arr 198 | 199 | 200 | # extract phone no using regex 201 | def get_phoneNumber(text): 202 | ''' Matches 3334445555, 333.444.5555, 333-444-5555, 203 | 333 444 5555, (333) 444 5555 and all combinations thereof, 204 | like 333 4445555, (333)4445555 or 333444-5555. 205 | Does not match international notation +13334445555, 206 | but matches domestic part in +1 333 4445555. 207 | using regex for extracting phone numbers 208 | then pass that compiled regex to get_phoneNumbers 209 | function and returns a string of phone numbers 210 | present in the text 211 | ''' 212 | 213 | phone_number = "" 214 | regex = re.compile(r"\(?\b[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}\b") # regex to match the pattern of phone no 215 | for phoneNumber in get_phoneNumbers(text, regex): # get a list of all phone no present present using function get_phoneNumbers 216 | phone_number = phone_number + phoneNumber + "\n" # create a string of phone no from the list returned 217 | return phone_number 218 | 219 | 220 | def get_phoneNumbers(s, regex): 221 | ''' returns all the phone numbers present 222 | in the input string 223 | ''' 224 | return (phoneNumber for phoneNumber in re.findall(regex, s)) # using the regex provided in function get_phoneNumber extract all phone no 225 | 226 | 227 | def remaining_msg(msg, fetched): 228 | '''to return a list of the message 229 | lines that hasn't been printed yet 230 | msg - list that is our mail body 231 | fetched - list that has been fetched and which needs 232 | to be removed from msg list 233 | 234 | ---- LOOP 1 description ---- 235 | ex- suppose we fetched 'Ram' from 'Ram is going to school'. 236 | So 'Ram'(element in fetched list) is a small part of 'Ram is going to school'(element in msg list). 237 | Hence fetched list element is smaller than or just a small part of msg list elements. 238 | Hence LOOP 1 checks for every such element in fetched list and helps to remove it from msg list 239 | 240 | ---- LOOP 2 description ---- 241 | ex - Suppose we fetched "3055 Wilshire Blvd., 12th Floor Los Angeles, CA 90010" from 242 | msg list "3055 Wilshire Blvd., 12th Floor" , "Los Angeles, CA 90010" 243 | Clearly fetched element is combination of two elements of msg list and hence bigger than 244 | both the elements so LOOP 2 searches for msg list elements(smaller) from the fethced list 245 | elements(bigger) and helps to remove it. 246 | ''' 247 | 248 | remains = [] # to contain the lines that need to be removed 249 | 250 | try: 251 | msg = [x.strip() for x in msg] # to remove the whitespaces from msg list 252 | fetched = [x.strip() for x in fetched] # to remove the whitespaces from fetched list 253 | msg = list(filter(lambda a: a != '', msg)) # to filter out '' kinda strings remained in msg list 254 | fetched = list(filter(lambda a: a != '', fetched)) # to filter out '' kinda strings remained in fetched list 255 | except: # if there is no whitespaces 256 | msg = [str(x) for x in msg] # first convert the raw msg list elements as string 257 | fetched = [str(x) for x in fetched] # convert the raw fetched list elements as string 258 | msg = list(filter(lambda a: a != '\r', msg)) # filter out '\r' kinda elements in msg list 259 | fetched = list(filter(lambda a: a != '\r', fetched)) # filter out '\r' kinda elements in msg list 260 | 261 | for fline in fetched: # check above for LOOP 1 description 262 | for line in msg: 263 | try: 264 | if line.find(fline) != -1: # if msg list contains any fetched list elements 265 | remains.append(line) # add it to the remains list 266 | break 267 | except: # if not contains then simply continue the loop 268 | pass 269 | 270 | for line in msg: # check above for LOOP 2 description 271 | for fline in fetched: 272 | try: 273 | if fline.find(line) != -1: # if fetched list contains any msg list elements 274 | remains.append(line) # add it to the remains list 275 | break 276 | except: # otherwise continue 277 | pass 278 | 279 | #print remains 280 | #print '\n', msg 281 | 282 | for line in remains: 283 | try: 284 | msg.remove(line) # now delete all the elements that we added in remains element 285 | except: 286 | pass # otherwise simply continue the loop 287 | return msg 288 | 289 | 290 | def location_fetch(msg): 291 | ''' the location ends with either state name or PIN 292 | using that this function checks for the words in each line 293 | if it contains the state then it will return the line 294 | ''' 295 | locs = [] # to add location if there is any 296 | for line in msg: 297 | linen = line.upper() 298 | if linen.find('ADDRESS') != -1: # check the line if it starts with 'ADDRESS' ex- 'ADDRESS: Los Angeles, CA 90010' 299 | locs.append(line) # include the line 300 | break 301 | for line in msg: 302 | words = line.split() # divide the msg lines into words 303 | for word in words: 304 | if word in states: # check if the words contains any US states name which is present in info.py file 305 | locs.append(line) # add the line 306 | return ' '.join(locs) # return the line as string 307 | 308 | 309 | def clear(): 310 | os.system('cls' if os.name == 'nt' else 'clear') # to refresh the screen i.e makes the screen blank 311 | 312 | 313 | def welcome(): 314 | '''shows the navigation menu for the tool''' 315 | print '\n' 316 | print '>> Enter \'n\' to check NEXT mail' 317 | print '>> Enter \'p\' to check PREVIOUS mail' 318 | print '>> Enter \'q\' to QUIT' 319 | 320 | 321 | if __name__ == '__main__': 322 | main() # run the file 323 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/remove_sig.py: -------------------------------------------------------------------------------- 1 | import talon 2 | from talon import signature as sig 3 | from talon.signature.bruteforce import extract_signature 4 | # don't forget to init the library first 5 | # it loads machine learning classifiers 6 | talon.init() 7 | 8 | # text1, text2, text3 are test cases which can used in debugging otherwise they ain't use in our app 9 | text1 = '''(818) 212-8948 10 | DOL: 10/20/2017 & DOL: 6/2017 11 | 10906 Woodley Ave Granada Hills CA 12 | Client has two cases to sign 13 | 14 | -- 15 | Leslie Garcia, Intake Coordinator 16 | Akiva Niamehr LLP 17 | 10900 Wilshire Blvd. Ste. 930 | Los Angeles, CA 90024 18 | P: 424.653.1093 | F: 310.882.5444 19 | E: leslie@anattorneys.com 20 | ''' 21 | text3 = ''' 22 | Hi David, 23 | 24 | 25 | 26 | We need a witness statement for one of our files. Please see below for 27 | 28 | the list of questions. 29 | 30 | 31 | 32 | Witness name: Salina Ramos 33 | 34 | Phone: (818) 723-6578 35 | 36 | 37 | 38 | 39 | -- 40 | Abhinav Anand, 41 | +91 8461077468 42 | ABV-IIITM, GWALIOR, MP, 474015 43 | ''' 44 | text2 = """Annette Anderson, 45 | 11833 Spring Laurel DR 46 | Charlotte, NC 28215 47 | 704-724-4697 48 | 49 | Client is a referral from our chiro- she is there now about to have her appointment. Please reach out in the next hour! 50 | 51 | Respectfully, 52 | 53 | Lacie N. Johnson 54 | Intake Paralegal 55 | Law Offices of Shane Smith, PC 56 | 263 Hwy 74 N 57 | Peachtree City, GA 30269 58 | 59 | 770.487.8999 ext. 42 60 | 770.631.7667 fax 61 | """ 62 | 63 | def remove_signature(message): 64 | '''takes the message as string 65 | and returns a string removing signature 66 | ''' 67 | msge = message.split('\n') # break the message in line 68 | try: 69 | msg = [x.rstrip() for x in msge] # remove the white spaces 70 | except: 71 | pass # otherwise proceed 72 | message = '\n'.join(msg) # form a string from the msg list 73 | 74 | if '--' in msg: # method 1 by checking the occurence of '--' in msg list 75 | text, signature = extract_signature(message) # extract the filtered text and signature 76 | else: #METHOD 2 by using ML way 77 | text, signature = sig.extract(message, sender='john.doe@example.com') # extract the text and signature, the sender argument is necessary but any fake email id can be used 78 | 79 | return text 80 | 81 | 82 | # print remove_signature(text1) 83 | # print '\n\n' 84 | # print remove_signature(text3) 85 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/remove_sig.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/MAIN APP/remove_sig.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/stopwords_filter.py: -------------------------------------------------------------------------------- 1 | from nltk.corpus import stopwords 2 | from nltk.tokenize import word_tokenize 3 | 4 | stop_words = set(stopwords.words('english')) # setting the language 5 | 6 | 7 | def process_names(names): 8 | '''takes a input list 9 | and removes all the stopwords 10 | ''' 11 | 12 | line = ' '.join(names) # create a string out of the list 13 | word_tokens = word_tokenize(line) # tokenize the string 14 | 15 | filtered_sentence = [w for w in word_tokens if not w in stop_words] # filtering the words 16 | 17 | return filtered_sentence 18 | 19 | 20 | # ** Just a test case ** 21 | a = ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 22 | 'off', 'the', 'stop', 'words', 'filtration', '.'] 23 | 24 | -------------------------------------------------------------------------------- /KS/MAIN APP_after/MAIN APP/stopwords_filter.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/MAIN APP/stopwords_filter.pyc -------------------------------------------------------------------------------- /KS/MAIN APP_after/app_re_GS.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/app_re_GS.zip -------------------------------------------------------------------------------- /KS/MAIN APP_after/main_app_3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/main_app_3.zip -------------------------------------------------------------------------------- /KS/MAIN APP_after/main_app_name2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN APP_after/main_app_name2.zip -------------------------------------------------------------------------------- /KS/MAIN_APP_before.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN_APP_before.zip -------------------------------------------------------------------------------- /KS/MAIN_APP_before/address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import pyap 4 | 5 | # below test_address, t3, test variable is a test case which can used in debugging otherwise it ain't used in our app 6 | test_address = """ 7 | David, 8 | 9 | We need a witness statement for one of our files. Please see below for 10 | the list of questions. 11 | 12 | Witness name: Salina Ramos 13 | Phone: (818) 723-6578 14 | 15 | 16 | Sincerely, 17 | 18 | Jackie Levine 19 | Assistant to Kyle K. Madison 20 | 21 | 22 | 23 | 11111 Santa Monica Blvd, Suite 100 24 | Los Angeles, CA 90025 25 | (310) 201-7676 (Office) 26 | (310) 744-0111 (Fax) 27 | 28 | The information in this e-mail (including attachments, if any) is 29 | considered confidential and is intended only for the recipient(s) listed 30 | above. Any review, use, disclosure, distribution or copying of this e-mail 31 | is prohibited except by or on behalf of the intended recipient. If you 32 | have received this email in error, 33 | """ 34 | test = ''' 35 | Hi David, 36 | 37 | Please send someone to sign: 38 | 39 | Maria Reyes 40 | Ph: 909-246-5391 (SPANISH) 41 | Address: 4138 Mission Blvd Space 58, Montclair, CA 91763 42 | DOL 01/08/2018 43 | 44 | Thank you 45 | 46 | 47 | ''' 48 | t2 = ''' 49 | Hello Team, 50 | 51 | We have a family that was involved in a MVA and needs to be contacted to set up an appointment for tomorrow, clients prefer at 11:00 a.m. 52 | 53 | Here is the contact person/client and location of sign-up, please note adult clients areSpanish speaking only: 54 | 55 | Jose A. Rios 56 | *400 Palm Avenue* 57 | *Watsonville, CA 95076* 58 | (831) 234-3634 59 | 60 | Date of Accident: 12/17/17 61 | 62 | Clients: 63 | 64 | 1. Juan R. Vega – driver 65 | 2. Jose A. Rios – passenger & vehicle owner 66 | 3. Enriqueta Rios – passenger & wife to Jose Rios 67 | 4. Elizabeth Rios – passenger & daughter to Jose Rios [she has down syndrome, Jose Rios will be her legal guardian and will answer questions on her behalf] 68 | 5. Roxanna Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 69 | 6. Iliana Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 70 | 71 | All adult clients will be at the above address, we are waiting to confirm if the father of both minors will be present, if not a separate meeting will be necessary. 72 | 73 | ''' 74 | t3 = ''' 75 | Jose A. Rios 76 | *400 Palm Avenue* 77 | *Watsonville, CA 95076* 78 | ''' 79 | def preprocess(arr_body): 80 | '''raw string can be of type 81 | '*Washington DC, 848101*' 82 | So it can't be fetched by the pyap module 83 | so refine the format of address 84 | ''' 85 | 86 | new_arr = [] 87 | for line in arr_body: 88 | line = line.replace('*', '') # replace '*' with '' 89 | new_arr.append(line) # add the refined line to the list 90 | return new_arr 91 | 92 | def fetch_address(arr_body): 93 | '''takes input list of body 94 | and extract address from it 95 | ''' 96 | msg_body = preprocess(arr_body) # refine the body 97 | msg_body = '\n'.join(msg_body) # make a string out of the list 98 | addresses = pyap.parse(msg_body, country='US') # selecting the country as 'US' parse the body and extract address 99 | location = [] # to include the address 100 | 101 | try: # if addresses contains any element 102 | for address in addresses: 103 | # shows found address 104 | location.append(address) # apppend the address 105 | # print address 106 | except: # if no elements simply pass 107 | pass 108 | return location 109 | 110 | #print(address.as_dict()) 111 | # print fetch_address(t3) 112 | -------------------------------------------------------------------------------- /KS/MAIN_APP_before/address.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN_APP_before/address.pyc -------------------------------------------------------------------------------- /KS/MAIN_APP_before/filters.py: -------------------------------------------------------------------------------- 1 | # unwanted words in subjects 2 | subject_items = [ 3 | 'URGENT', 4 | 'SIGN', 5 | 'UP', 6 | 'RETAINER', 7 | 'PICKUP', 8 | 'NEW', 9 | 'CASE', 10 | 'CLIENT', 11 | 'LEAD', 12 | ':', 13 | '-', 14 | 'RE', 15 | 'FWD', 16 | 'FW', 17 | 'SIGN-UP' 18 | 19 | ] 20 | 21 | # unwanted keywords in phone number 22 | phone_items = [ 23 | '(', 24 | ')', 25 | '-' 26 | ] 27 | 28 | # words to look for for signatures 29 | sign_items_pre = [ 30 | 'SIGNATURE', 31 | 'SIGN' 32 | ] 33 | 34 | # number of signatures possible 35 | sign_items_post = [ 36 | 'ONE', 37 | 'TWO', 38 | 'THREE', 39 | 'FOUR', 40 | 'FIVE', 41 | 'SIX', 42 | 'SEVEN', 43 | 'EIGHT', 44 | 'NINE', 45 | 'TEN', 46 | 'ELEVEN', 47 | 'TWELVE', 48 | '1', 49 | '2', 50 | '3', 51 | '4', 52 | '5', 53 | '6', 54 | '7', 55 | '8', 56 | '9', 57 | '10', 58 | '11', 59 | '12' 60 | ] -------------------------------------------------------------------------------- /KS/MAIN_APP_before/filters.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN_APP_before/filters.pyc -------------------------------------------------------------------------------- /KS/MAIN_APP_before/info.py: -------------------------------------------------------------------------------- 1 | us_states = ['WA', 'Washington', 'WI', 'Wisconsin', 2 | 'WV', 'West Virginia', 'FL', 3 | 'Florida', 'WY', 'Wyoming', 'NH', 4 | 'New Hampshire', 'NJ', 'New Jersey', 5 | 'NM', 'New Mexico', 'NA', 6 | 'NC', 'North Carolina', 7 | 'ND', 'North Dakota', 'NE', 8 | 'Nebraska', 'NY', 'New York', 'RI', 9 | 'Rhode Island', 'NV', 'Nevada', 10 | 'GU', 'Guam', 'CO', 'Colorado', 11 | 'CA', 'California', 'GA', 'Georgia', 12 | 'CT', 'Connecticut', 'OK', 13 | 'Oklahoma', 'OH', 'Ohio', 'KS', 14 | 'Kansas', 'SC', 'South Carolina', 15 | 'KY', 'Kentucky', 'OR', 'Oregon', 16 | 'SD', 'South Dakota', 'DE', 17 | 'Delaware', 'DC', 18 | 'District of Columbia', 'HI', 19 | 'Hawaii', 'PR', 'Puerto Rico', 'TX', 20 | 'Texas', 'LA', 'Louisiana', 'TN', 21 | 'Tennessee', 'PA', 'Pennsylvania', 22 | 'VA', 'Virginia', 'VI', 23 | 'Virgin Islands', 'AK', 'Alaska', 24 | 'AL', 'Alabama', 'AS', 25 | 'American Samoa', 'AR', 'Arkansas', 26 | 'VT', 'Vermont', 'IL', 'Illinois', 27 | 'IN', 'Indiana', 'IA', 'Iowa', 'AZ', 28 | 'Arizona', 'ID', 'Idaho', 'ME', 29 | 'Maine', 'MD', 'Maryland', 'MA', 30 | 'Massachusetts', 'UT', 'Utah', 'MO', 31 | 'Missouri', 'MN', 'Minnesota', 'MI', 32 | 'Michigan', 'MT', 'Montana', 'MP', 33 | 'Northern Mariana Islands', 'MS', 34 | 'Mississippi' 35 | ] 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /KS/MAIN_APP_before/info.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN_APP_before/info.pyc -------------------------------------------------------------------------------- /KS/MAIN_APP_before/name.py: -------------------------------------------------------------------------------- 1 | import re 2 | import nltk 3 | from nltk.corpus import stopwords 4 | stop = stopwords.words('english') # to set the words selection as ENGLISH 5 | 6 | # below document AND check variables is a test case which can used in debugging otherwise it ain't used in our app 7 | document=""" 8 | David, 9 | 10 | I need this signed up ASAP in Santa Cruz. Brain injury. Wi 11 | 12 | Joshua Orosco 13 | Tel#: 831-201 7096 14 | 15 | Needs a call right now to schedule time and location 16 | 17 | Reza 18 | 19 | 20 | -- 21 | Reza Torkzadeh 22 | Office: 888.222.8286 23 | Mobile: 949.698.8087 24 | 25 | Please note: This message is being sent via mobile phone. Please excuse any informalities, brevity, spelling and grammatical errors. 26 | """ 27 | check = ['Annette Anderson,', 28 | 'The client is a referral from our chiro- she is there now about to have her', 29 | 'appointment. Please reach out in the next hour!', 'Respectfully,'] 30 | 31 | def extract_names(document): 32 | '''takes a string input and 33 | print a set of all the names present in it 34 | ''' 35 | document = '\n'.join(document) # create a string from the document list 36 | document = ' '.join([i for i in document.split() if i not in stop]) 37 | sentences = nltk.sent_tokenize(document) # tokenizing the document 38 | sentences = [nltk.word_tokenize(sent) for sent in sentences] # now word_tokenizing the sentences 39 | sentences = [nltk.pos_tag(sent) for sent in sentences] # pos_tagging the sentences 40 | names = [] # create a list to contain names 41 | for tagged_sentence in sentences: 42 | for chunk in nltk.ne_chunk(tagged_sentence): 43 | if type(chunk) == nltk.tree.Tree: # check the chunk type 44 | if chunk.label() == 'PERSON': # if the chunk type is PERSON 45 | names.append(' '.join([c[0] for c in chunk])) # add such names or chunks 46 | 47 | 48 | names_unique=set(names) # make sure there is unique elements 49 | # print(names_unique) 50 | my_list = list(name.upper() for name in names_unique) # now create a list from the set names_unique 51 | return my_list 52 | 53 | #print extract_names(check) 54 | -------------------------------------------------------------------------------- /KS/MAIN_APP_before/name.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN_APP_before/name.pyc -------------------------------------------------------------------------------- /KS/MAIN_APP_before/new_app.py: -------------------------------------------------------------------------------- 1 | # Reading inbox emails from CLI. 2 | # !/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | 9 | from info import us_states as states 10 | from address import fetch_address 11 | from name import extract_names 12 | from remove_sig import remove_signature 13 | from filters import (subject_items, phone_items, 14 | sign_items_post, sign_items_pre 15 | ) 16 | from stopwords_filter import process_names 17 | from dol_extractor import extract_dol 18 | 19 | # some constant datas to initialize with 20 | imaplib._MAXLINE = 400000 21 | 22 | ORG_EMAIL = "@gmail.com" 23 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 24 | FROM_PWD = getpass.getpass() 25 | SMTP_SERVER = "imap.gmail.com" # varies depending on the imap server 26 | SMTP_PORT = 993 27 | 28 | 29 | i = 0 # a counter to to move to next or previous mail 30 | body_fetched = [] # to contain all the lines which has been printed already 31 | 32 | 33 | def main(): 34 | ''' connect with the server 35 | fetch the mails and do the preprocessing 36 | ''' 37 | global i, body_fetched, email_message 38 | clear() # to clear the screen before fetching the mails 39 | # login 40 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) # connect with the server 41 | mail.login(FROM_EMAIL, FROM_PWD) # loggin in 42 | mail.list() # get a list of mails 43 | mail.select('inbox') # getting from the INBOX 44 | inp = 'n' # an inital counter for the first mail 45 | 46 | # start fetching mails one by one 47 | while (inp != 'q'): 48 | print('Fetching mails. Please wait...') 49 | if inp == 'n': # fetch next mail 50 | i += 1 51 | elif inp == 'p' and i != 1: # fetch previous mail, making sure it's not the first mail already 52 | i -= 1 53 | else: # in case user gives some invalid input 54 | print('Please enter valid input.') 55 | 56 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 57 | latest_email_uid = data[0].split()[-i] # fetch list of mails id 58 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') # iterate through the email and fetch the email using RFC822 protocol 59 | raw_email = data[0][1] # to get raw mails from the data fetched 60 | email_message = email.message_from_string(raw_email) # convert it as a string 61 | 62 | clear() # clear screen and print mail 63 | print 'To:', email_message['To'] # print TO of the mail 64 | print 'Sent from:', email_message['From'] # print FROM of the mail 65 | print 'Date:', email_message['Date'] # print DATE of the mail 66 | 67 | # preprocess the subject to remove unwanted words 68 | subject = [p.upper() for p in email_message['Subject'].split()] # break subject into list 69 | for item in subject_items: # iterate n delete the unwanted items 70 | if item in subject: 71 | try: 72 | subject.remove(item) 73 | except: 74 | pass 75 | 76 | subject = ' '.join(subject) 77 | print 'Subject:', subject # print SUBJECT of the mail 78 | 79 | print '\n' 80 | maintype = email_message.get_content_maintype() # check the type of mail 81 | 82 | if maintype == 'multipart': # get the body of the mail if type is 'multipart' 83 | body = email_message.get_payload()[0].get_payload() # to get the plain text only 84 | elif maintype == 'text': # get the body if the mail if type is 'text' 85 | body = email_message.get_payload()[0] 86 | 87 | 88 | body = remove_signature(body) # preprocessing the body to remove signature 89 | 90 | body_fetched = [] # to keep the track of things we gonna extract from the body like DOL, phone no. 91 | dols_in = extract_dol_in(body) 92 | dols = extract_dol(dols_in) # extract DOL 93 | phone_num = get_phoneNumber(body) # extract phone no 94 | 95 | # removing unwanted keywords from phone no 96 | phone_no = list(phone_num) 97 | for item in phone_items: 98 | if item in phone_no: 99 | phone_no = list(filter(lambda a: a != item, phone_no)) 100 | 101 | phone_no = ''.join(phone_no) 102 | 103 | # adding the items in the body_fetched list 104 | body_fetched.extend(phone_num.split('\n')) 105 | body_fetched.append 106 | 107 | print 'Phone Number: ', phone_no 108 | 109 | for dol in dols: # print the DOLs 110 | print str(dol) 111 | 112 | print '\n' 113 | 114 | remaining_body_location = remaining_msg(body.split('\n'), body_fetched) # get the body after removing what we extracted 115 | 116 | location = fetch_address(remaining_body_location) # extract location 117 | 118 | if len(location) != 0: # if some location is extracted by ML method 119 | for address in location: 120 | body_fetched.append(str(address)) # add the location to the body_fetched list 121 | print 'Address: ', address # print address 122 | else: # if no location is extracted then try the brute force 123 | loc = location_fetch(remaining_body_location) # extract location 124 | body_fetched.append(str(loc)) # add it to the list 125 | loc = loc.split() # create a list breaking the address line in words 126 | new_locs = [] # create a list to add the words in location 127 | for lo in loc: # if the location line starts with 'ADDRESS' then remove it and add the remaining words in new_locs list 128 | if 'ADDRESS' not in lo.upper(): 129 | new_locs.append(lo) 130 | 131 | print 'Address: ', ' '.join(new_locs) # print the location as a string forming from the new_locs list 132 | 133 | remaining_body_name = remaining_msg(remaining_body_location, body_fetched) # get the body after removing what we extracted 134 | 135 | # filtering out no of sign/cases 136 | req_line = '' 137 | for item in sign_items_pre: 138 | for part in remaining_body_name: 139 | if item in part.upper(): 140 | req_line = part 141 | break 142 | 143 | req_item = '' 144 | for item in sign_items_post: 145 | if item in req_line.split(): 146 | req_item = item 147 | break 148 | 149 | print 'NO OF CASES/SIGNS: ', req_item 150 | print '\n' 151 | try: 152 | remaining_body_name = process_names(remaining_body_name) # remove the stopwords 153 | except: 154 | pass 155 | 156 | names = extract_names(remaining_body_name) # extract the names from the remaining body 157 | 158 | print '\n' 159 | 160 | 161 | print 'Name: ', 162 | if len(remaining_body_name) != 0: # if there are names extracted 163 | if 'DAVID' in remaining_body_name[0].upper(): # if first line contains DAVID ignore it. 164 | names.remove('DAVID') 165 | 166 | for j in range(len(names)): # print names 167 | print names[j] 168 | 169 | welcome() # print the welcome message 170 | inp = raw_input('>> Enter your choice: ').lower() # take the input for next/previous mails 171 | 172 | 173 | def extract_dol_in(body): 174 | '''splitting the message into lines 175 | and extracting the lines with DOL in it 176 | ''' 177 | 178 | dol_matches = ['DOL', 'DATE OF LOSS', 'DATE OF ACCIDENT'] # creating the possible ways of writing DOLs 179 | body = body.split('\n') # create a list based on the every next line 180 | dol_arr = [] # create a list to add the DOL if there is any in the list 181 | for line in body: 182 | for dol in dol_matches: 183 | if dol in line.upper(): # if any DOL or similar words are there in body then add it to the list 184 | dol_arr.append(line) 185 | return dol_arr 186 | 187 | 188 | # extract phone no using regex 189 | def get_phoneNumber(text): 190 | ''' Matches 3334445555, 333.444.5555, 333-444-5555, 191 | 333 444 5555, (333) 444 5555 and all combinations thereof, 192 | like 333 4445555, (333)4445555 or 333444-5555. 193 | Does not match international notation +13334445555, 194 | but matches domestic part in +1 333 4445555. 195 | using regex for extracting phone numbers 196 | then pass that compiled regex to get_phoneNumbers 197 | function and returns a string of phone numbers 198 | present in the text 199 | ''' 200 | 201 | phone_number = "" 202 | regex = re.compile(r"\(?\b[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}\b") # regex to match the pattern of phone no 203 | for phoneNumber in get_phoneNumbers(text, regex): # get a list of all phone no present present using function get_phoneNumbers 204 | phone_number = phone_number + phoneNumber + "\n" # create a string of phone no from the list returned 205 | return phone_number 206 | 207 | 208 | def get_phoneNumbers(s, regex): 209 | ''' returns all the phone numbers present 210 | in the input string 211 | ''' 212 | return (phoneNumber for phoneNumber in re.findall(regex, s)) # using the regex provided in function get_phoneNumber extract all phone no 213 | 214 | 215 | def remaining_msg(msg, fetched): 216 | '''to return a list of the message 217 | lines that hasn't been printed yet 218 | msg - list that is our mail body 219 | fetched - list that has been fetched and which needs 220 | to be removed from msg list 221 | 222 | ---- LOOP 1 description ---- 223 | ex- suppose we fetched 'Ram' from 'Ram is going to school'. 224 | So 'Ram'(element in fetched list) is a small part of 'Ram is going to school'(element in msg list). 225 | Hence fetched list element is smaller than or just a small part of msg list elements. 226 | Hence LOOP 1 checks for every such element in fetched list and helps to remove it from msg list 227 | 228 | ---- LOOP 2 description ---- 229 | ex - Suppose we fetched "3055 Wilshire Blvd., 12th Floor Los Angeles, CA 90010" from 230 | msg list "3055 Wilshire Blvd., 12th Floor" , "Los Angeles, CA 90010" 231 | Clearly fetched element is combination of two elements of msg list and hence bigger than 232 | both the elements so LOOP 2 searches for msg list elements(smaller) from the fethced list 233 | elements(bigger) and helps to remove it. 234 | ''' 235 | 236 | remains = [] # to contain the lines that need to be removed 237 | 238 | try: 239 | msg = [x.strip() for x in msg] # to remove the whitespaces from msg list 240 | fetched = [x.strip() for x in fetched] # to remove the whitespaces from fetched list 241 | msg = list(filter(lambda a: a != '', msg)) # to filter out '' kinda strings remained in msg list 242 | fetched = list(filter(lambda a: a != '', fetched)) # to filter out '' kinda strings remained in fetched list 243 | except: # if there is no whitespaces 244 | msg = [str(x) for x in msg] # first convert the raw msg list elements as string 245 | fetched = [str(x) for x in fetched] # convert the raw fetched list elements as string 246 | msg = list(filter(lambda a: a != '\r', msg)) # filter out '\r' kinda elements in msg list 247 | fetched = list(filter(lambda a: a != '\r', fetched)) # filter out '\r' kinda elements in msg list 248 | 249 | for fline in fetched: # check above for LOOP 1 description 250 | for line in msg: 251 | try: 252 | if line.find(fline) != -1: # if msg list contains any fetched list elements 253 | remains.append(line) # add it to the remains list 254 | break 255 | except: # if not contains then simply continue the loop 256 | pass 257 | 258 | for line in msg: # check above for LOOP 2 description 259 | for fline in fetched: 260 | try: 261 | if fline.find(line) != -1: # if fetched list contains any msg list elements 262 | remains.append(line) # add it to the remains list 263 | break 264 | except: # otherwise continue 265 | pass 266 | 267 | #print remains 268 | #print '\n', msg 269 | 270 | for line in remains: 271 | try: 272 | msg.remove(line) # now delete all the elements that we added in remains element 273 | except: 274 | pass # otherwise simply continue the loop 275 | return msg 276 | 277 | 278 | def location_fetch(msg): 279 | ''' the location ends with either state name or PIN 280 | using that this function checks for the words in each line 281 | if it contains the state then it will return the line 282 | ''' 283 | locs = [] # to add location if there is any 284 | for line in msg: 285 | linen = line.upper() 286 | if linen.find('ADDRESS') != -1: # check the line if it starts with 'ADDRESS' ex- 'ADDRESS: Los Angeles, CA 90010' 287 | locs.append(line) # include the line 288 | break 289 | for line in msg: 290 | words = line.split() # divide the msg lines into words 291 | for word in words: 292 | if word in states: # check if the words contains any US states name which is present in info.py file 293 | locs.append(line) # add the line 294 | return ' '.join(locs) # return the line as string 295 | 296 | 297 | def clear(): 298 | os.system('cls' if os.name == 'nt' else 'clear') # to refresh the screen i.e makes the screen blank 299 | 300 | 301 | def welcome(): 302 | '''shows the navigation menu for the tool''' 303 | print '\n' 304 | print '>> Enter \'n\' to check NEXT mail' 305 | print '>> Enter \'p\' to check PREVIOUS mail' 306 | print '>> Enter \'q\' to QUIT' 307 | 308 | 309 | if __name__ == '__main__': 310 | main() # run the file 311 | -------------------------------------------------------------------------------- /KS/MAIN_APP_before/remove_sig.py: -------------------------------------------------------------------------------- 1 | import talon 2 | from talon import signature as sig 3 | from talon.signature.bruteforce import extract_signature 4 | # don't forget to init the library first 5 | # it loads machine learning classifiers 6 | talon.init() 7 | 8 | # text1, text2, text3 are test cases which can used in debugging otherwise they ain't use in our app 9 | text1 = '''(818) 212-8948 10 | DOL: 10/20/2017 & DOL: 6/2017 11 | 10906 Woodley Ave Granada Hills CA 12 | Client has two cases to sign 13 | 14 | -- 15 | Leslie Garcia, Intake Coordinator 16 | Akiva Niamehr LLP 17 | 10900 Wilshire Blvd. Ste. 930 | Los Angeles, CA 90024 18 | P: 424.653.1093 | F: 310.882.5444 19 | E: leslie@anattorneys.com 20 | ''' 21 | text3 = ''' 22 | Hi David, 23 | 24 | 25 | 26 | We need a witness statement for one of our files. Please see below for 27 | 28 | the list of questions. 29 | 30 | 31 | 32 | Witness name: Salina Ramos 33 | 34 | Phone: (818) 723-6578 35 | 36 | 37 | 38 | 39 | -- 40 | Abhinav Anand, 41 | +91 8461077468 42 | ABV-IIITM, GWALIOR, MP, 474015 43 | ''' 44 | text2 = """Annette Anderson, 45 | 11833 Spring Laurel DR 46 | Charlotte, NC 28215 47 | 704-724-4697 48 | 49 | Client is a referral from our chiro- she is there now about to have her appointment. Please reach out in the next hour! 50 | 51 | Respectfully, 52 | 53 | Lacie N. Johnson 54 | Intake Paralegal 55 | Law Offices of Shane Smith, PC 56 | 263 Hwy 74 N 57 | Peachtree City, GA 30269 58 | 59 | 770.487.8999 ext. 42 60 | 770.631.7667 fax 61 | """ 62 | 63 | def remove_signature(message): 64 | '''takes the message as string 65 | and returns a string removing signature 66 | ''' 67 | msge = message.split('\n') # break the message in line 68 | try: 69 | msg = [x.rstrip() for x in msge] # remove the white spaces 70 | except: 71 | pass # otherwise proceed 72 | message = '\n'.join(msg) # form a string from the msg list 73 | 74 | if '--' in msg: # method 1 by checking the occurence of '--' in msg list 75 | text, signature = extract_signature(message) # extract the filtered text and signature 76 | else: #METHOD 2 by using ML way 77 | text, signature = sig.extract(message, sender='john.doe@example.com') # extract the text and signature, the sender argument is necessary but any fake email id can be used 78 | 79 | return text 80 | 81 | 82 | # print remove_signature(text1) 83 | # print '\n\n' 84 | # print remove_signature(text3) 85 | -------------------------------------------------------------------------------- /KS/MAIN_APP_before/remove_sig.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN_APP_before/remove_sig.pyc -------------------------------------------------------------------------------- /KS/MAIN_APP_before/stopwords_filter.py: -------------------------------------------------------------------------------- 1 | from nltk.corpus import stopwords 2 | from nltk.tokenize import word_tokenize 3 | 4 | stop_words = set(stopwords.words('english')) # setting the language 5 | 6 | 7 | def process_names(body): 8 | '''takes a input list of body 9 | and removes all the stopwords 10 | ''' 11 | new_body = [] 12 | 13 | for line in body: 14 | word_tokens = word_tokenize(line) # tokenize the string 15 | 16 | filtered_sentence = [w for w in word_tokens if not w in stop_words] # filtering the words 17 | line = ' '.join(line) 18 | new_body.append(line) 19 | 20 | return new_body 21 | 22 | 23 | # ** Just a test case ** 24 | a = ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 25 | 'off', 'the', 'stop', 'words', 'filtration', '.'] 26 | 27 | -------------------------------------------------------------------------------- /KS/MAIN_APP_before/stopwords_filter.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/MAIN_APP_before/stopwords_filter.pyc -------------------------------------------------------------------------------- /KS/address.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/address.pyc -------------------------------------------------------------------------------- /KS/app.py: -------------------------------------------------------------------------------- 1 | # Reading inbox emails from CLI. 2 | # !/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | from info import us_states as states 9 | 10 | # some required datas to initialize with 11 | imaplib._MAXLINE = 400000 12 | 13 | ORG_EMAIL = "@gmail.com" 14 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 15 | FROM_PWD = getpass.getpass() 16 | SMTP_SERVER = "imap.gmail.com" # varies depending on the imap server 17 | SMTP_PORT = 993 18 | 19 | i = 0 20 | 21 | def main(): 22 | global i 23 | clear() 24 | # login 25 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) 26 | mail.login(FROM_EMAIL, FROM_PWD) 27 | mail.list() 28 | mail.select('inbox') 29 | inp = 'n' 30 | 31 | # start fetching mails one by one 32 | while(inp!='q'): 33 | print('Fetching mails. Please wait...') 34 | if inp == 'n': 35 | i += 1 36 | elif inp == 'p' and i != 1: 37 | i -= 1 38 | else: 39 | print('Please enter valid input.') 40 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 41 | latest_email_uid = data[0].split()[-i] # fetch mails 42 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') 43 | raw_email = data[0][1] 44 | email_message = email.message_from_string(raw_email) 45 | 46 | clear() # clear screen and print mail 47 | print 'To:', email_message['To'] 48 | print 'Sent from:', email_message['From'] 49 | print 'Date:', email_message['Date'] 50 | print 'Subject:', email_message['Subject'] 51 | #print '*'*30, 'MESSAGE', '*'*30 52 | print '\n' 53 | maintype = email_message.get_content_maintype() 54 | #print maintype 55 | 56 | if maintype == 'multipart': # get the body of the mail 57 | body = email_message.get_payload()[0].get_payload() # to get the plain text only 58 | dols = extract_dol(body) 59 | phone_no = get_phoneNumber(body) 60 | 61 | print 'Phone Number: ', phone_no 62 | 63 | # remain = remaining_msg(body, phone_no, dols) 64 | loc = location(body) 65 | 66 | for dol in dols: 67 | print str(dol) 68 | 69 | print '\n' 70 | 71 | print 'Location: ',str(loc) 72 | 73 | elif maintype == 'text': 74 | line = email_message.get_payload()[ 0 ] 75 | dols = extract_dol(line) 76 | phone_no = get_phoneNumber(line) 77 | print 'Phone Number: ', phone_no 78 | remain = remaining_msg(line, phone_no, dols) 79 | 80 | for dol in dols: 81 | print str(dol) 82 | 83 | print '\n' 84 | 85 | for re in remain: 86 | print str(re) 87 | # print '*'*69 88 | welcome() 89 | inp = raw_input('>> Enter your choice: ').lower() 90 | 91 | # extract DOLs 92 | def extract_dol(string): 93 | ''' splitting the message into lines 94 | and extracting the lines with DOL in it ''' 95 | 96 | string = string.split('\n') 97 | dol_arr = [] 98 | for text in string: 99 | if "DOL" in text: 100 | dol_arr.append(text) 101 | return dol_arr 102 | 103 | 104 | # extract phone no using regex 105 | def get_phoneNumber(text): 106 | ''' Matches 3334445555, 333.444.5555, 333-444-5555, 107 | 333 444 5555, (333) 444 5555 and all combinations thereof, 108 | like 333 4445555, (333)4445555 or 333444-5555. 109 | Does not match international notation +13334445555, 110 | but matches domestic part in +1 333 4445555. 111 | using regex for extracting phone numbers 112 | then pass that compiled regex to get_phoneNumbers 113 | function and returns a string of phone numbers 114 | present in the text ''' 115 | 116 | phone_number = "" 117 | regex = re.compile(r"\(?\b[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}\b") 118 | for phoneNumber in get_phoneNumbers(text, regex): 119 | phone_number = phone_number + phoneNumber + "\n" 120 | return phone_number 121 | 122 | def get_phoneNumbers(s, regex): 123 | ''' returns all the phone numbers present 124 | in the input string ''' 125 | 126 | return (phoneNumber for phoneNumber in re.findall(regex, s)) 127 | 128 | def remaining_msg(msg, phone_no, dol): 129 | ''' with a purpose of fetching location 130 | we simply return whatever is remained in 131 | the message body''' 132 | 133 | msg = msg.split('\n') 134 | phone_no = phone_no.split() 135 | exclude = [] 136 | for line in msg: 137 | for no in phone_no: 138 | if no in line: 139 | exclude.append(line) 140 | dol = [str(a) for a in dol] 141 | exclude.extend(dol) 142 | return [remain for remain in msg if remain not in exclude] 143 | 144 | def location(msg): 145 | ''' the location ends with either state name or PIN 146 | using that this function checks for the words in each line 147 | if it contains the state then it will return the line''' 148 | 149 | msg = msg.split('\n') 150 | for line in msg: 151 | words = line.split() 152 | for word in words: 153 | if word in states: 154 | return line 155 | 156 | def clear(): 157 | os.system('cls' if os.name == 'nt' else 'clear') 158 | 159 | def welcome(): 160 | print '\n' 161 | print '>> Enter \'n\' to check NEXT mail' 162 | print '>> Enter \'p\' to check PREVIOUS mail' 163 | print '>> Enter \'q\' to QUIT' 164 | 165 | if __name__ == '__main__': 166 | main() 167 | -------------------------------------------------------------------------------- /KS/check_sig.py: -------------------------------------------------------------------------------- 1 | from remove_sig import remove_signature 2 | message = """Annette Anderson, 3 | 11833 Spring Laurel DR 4 | Charlotte, NC 28215 5 | 704-724-4697 6 | 7 | Client is a referral from our chiro- she is there now about to have her appointment. Please reach out in the next hour! 8 | 9 | Respectfully, 10 | 11 | Lacie N. Johnson 12 | Intake Paralegal 13 | Law Offices of Shane Smith, PC 14 | 263 Hwy 74 N 15 | Peachtree City, GA 30269 16 | 17 | 770.487.8999 ext. 42 18 | 770.631.7667 fax 19 | """ 20 | 21 | print remove_signature(message) 22 | -------------------------------------------------------------------------------- /KS/checks/address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import pyap 4 | test_address = """ 5 | Hi David, 6 | 7 | Please send someone to sign: 8 | 9 | Maria Reyes 10 | Ph: 909-246-5391 (SPANISH) 11 | Address: 4138 Mission Blvd Space 58, Montclair, CA 91763 12 | DOL 01/08/2018 13 | 14 | Thank you 15 | """ 16 | 17 | t2 = ''' 18 | Hello Team, 19 | 20 | We have a family that was involved in a MVA and needs to be contacted to set up an appointment for tomorrow, clients prefer at 11:00 a.m. 21 | 22 | Here is the contact person/client and location of sign-up, please note adult clients areSpanish speaking only: 23 | 24 | Jose A. Rios 25 | 400 Palm Avenue 26 | Watsonville, CA 95076 27 | (831) 234-3634 28 | 29 | Date of Accident: 12/17/17 30 | 31 | Clients: 32 | 33 | 1. Juan R. Vega – driver 34 | 2. Jose A. Rios – passenger & vehicle owner 35 | 3. Enriqueta Rios – passenger & wife to Jose Rios 36 | 4. Elizabeth Rios – passenger & daughter to Jose Rios [she has down syndrome, Jose Rios will be her legal guardian and will answer questions on her behalf] 37 | 5. Roxanna Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 38 | 6. Iliana Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 39 | 40 | All adult clients will be at the above address, we are waiting to confirm if the father of both minors will be present, if not a separate meeting will be necessary. 41 | 42 | I will be sending the prepared retainers on this group of clients under separate cover. Thank you. 43 | 44 | 45 | ''' 46 | t3 = ''' 47 | Address: VISTA CALIFORNIA 92081 48 | ''' 49 | #print test_address 50 | addresses = pyap.parse(t3, country='US') 51 | for address in addresses: 52 | # shows found address 53 | print(address) 54 | 55 | #print(address.as_dict()) 56 | -------------------------------------------------------------------------------- /KS/checks/name.py: -------------------------------------------------------------------------------- 1 | import re 2 | import nltk 3 | from nltk.corpus import stopwords 4 | stop = stopwords.words('english') 5 | 6 | document=""" 7 | Annette Anderson, 8 | 9 | I need this signed up ASAP in Santa Cruz. Brain injury. Wi 10 | 11 | 12 | Tel#: 831-201 7096 13 | 14 | Needs a call right now to schedule time and location 15 | 16 | Reza 17 | 18 | 19 | -- 20 | 21 | Reza Torkzadeh 22 | Office: 888.222.8286 23 | Mobile: 949.698.8087 24 | 25 | Please note: This message is being sent via mobile phone. Please excuse any informalities, brevity, spelling and grammatical errors. 26 | """ 27 | 28 | document = ' '.join([i for i in document.split() if i not in stop]) 29 | sentences = nltk.sent_tokenize(document) 30 | sentences = [nltk.word_tokenize(sent) for sent in sentences] 31 | sentences = [nltk.pos_tag(sent) for sent in sentences] 32 | names = [] 33 | for tagged_sentence in sentences: 34 | for chunk in nltk.ne_chunk(tagged_sentence): 35 | if type(chunk) == nltk.tree.Tree: 36 | if chunk.label() == 'PERSON': 37 | names.append(' '.join([c[0] for c in chunk])) 38 | 39 | 40 | names_unique=set(names) 41 | print(names_unique) 42 | my_list = list(names_unique) 43 | print(my_list) 44 | -------------------------------------------------------------------------------- /KS/checks/new_names.py: -------------------------------------------------------------------------------- 1 | text = """ 2 | Annette Anderson, 3 | 4 | I need this signed up ASAP in Santa Cruz. Brain injury. Wi 5 | 6 | 7 | Tel#: 831-201 7096 8 | 9 | Needs a call right now to schedule time and location 10 | 11 | Reza 12 | 13 | 14 | -- 15 | 16 | Reza Torkzadeh 17 | Office: 888.222.8286 18 | Mobile: 949.698.8087 19 | 20 | Please note: This message is being sent via mobile phone. Please excuse any informalities, brevity, spelling and grammatical errors. 21 | """ 22 | 23 | from nameparser import HumanName 24 | name = HumanName(text) 25 | print name.full_name 26 | -------------------------------------------------------------------------------- /KS/checks/sig.py: -------------------------------------------------------------------------------- 1 | from talon.signature.bruteforce import extract_signature 2 | text = '''(818) 212-8948 3 | DOL: 10/20/2017 & DOL: 6/2017 4 | 10906 Woodley Ave Granada Hills CA 5 | Client has two cases to sign 6 | 7 | -- 8 | Leslie Garcia, Intake Coordinator 9 | Akiva Niamehr LLP 10 | 10900 Wilshire Blvd. Ste. 930 | Los Angeles, CA 90024 11 | P: 424.653.1093 | F: 310.882.5444 12 | E: leslie@anattorneys.com 13 | ''' 14 | text, signature = extract_signature(text) 15 | print text 16 | 17 | -------------------------------------------------------------------------------- /KS/checks/sig_ml.py: -------------------------------------------------------------------------------- 1 | import talon 2 | # don't forget to init the library first 3 | # it loads machine learning classifiers 4 | talon.init() 5 | 6 | from talon import signature 7 | 8 | 9 | message = """Annette Anderson, 10 | 11833 Spring Laurel DR 11 | Charlotte, NC 28215 12 | 704-724-4697 13 | 14 | Client is a referral from our chiro- she is there now about to have her appointment. Please reach out in the next hour! 15 | 16 | Respectfully, 17 | 18 | Lacie N. Johnson 19 | Intake Paralegal 20 | Law Offices of Shane Smith, PC 21 | 263 Hwy 74 N 22 | Peachtree City, GA 30269 23 | 24 | 770.487.8999 ext. 42 25 | 770.631.7667 fax 26 | """ 27 | 28 | text, signature = signature.extract(message, sender='john.doe@example.com') 29 | print text 30 | -------------------------------------------------------------------------------- /KS/checks/xiny.py: -------------------------------------------------------------------------------- 1 | fetched = ['909-246-5391', '', 'DOL 01/08/2018\r', 2 | 'Address: 4138 Mission Blvd Space 58, Montclair, CA 91763\r'] 3 | 4 | body = ['Hi i am ram,\r', '\r', '\r', '\r', 'Please send someone to sign:\r', '\r', '\r', '\r', 'Maria Reyes\r', '\r', 5 | 'Ph: 909-246-5391 (SPANISH)\r', '\r', 6 | 'Address: 4138 Mission Blvd Space 58, Montclair, CA 91763\r', 7 | '\r', 'DOL 01/08/2018\r', '\r', '\r', '\r', 'Thank you\r', ''] 8 | f2 = ['704-724-4697', '', '11833 Spring Laurel DR Charlotte, NC 28215'] 9 | 10 | b2 = ['11833 Spring Laurel DR\r', '\r', 'Charlotte, NC 28215\r', '\r', '\r', '\r', '\r', 'The client is a referral from our chiro- she is there now about to have her\r', 11 | 'appointment. Please reach out in the next hour!\r', '\r', '\r', '\r', 'Respectfully,\r', ''] 12 | def remaining_msg(msg, fetched): 13 | ''' 14 | to return a list of the message 15 | lines that hasn't been printed yetq 16 | ''' 17 | 18 | # msg = msg.split('\n') 19 | remains = [] # to contain the remaining body 20 | # print remains 21 | #msg = [x.strip() for x in msg] 22 | #fetched = [x.strip() for x in fetched] 23 | # print 'fetched ', fetched 24 | for fline in fetched: 25 | for line in msg: 26 | if line.find(fline) != -1: 27 | # print 'line: ', line 28 | remains.append(line) 29 | break 30 | #print 'remains1 ', remains 31 | 32 | for line in msg: 33 | for fline in fetched: 34 | if fline.find(line) != -1: 35 | # print 'line: ', line 36 | remains.append(line) 37 | break 38 | 39 | 40 | #print 'remains2 ', remains 41 | #print '\n', msg 42 | for line in remains: 43 | try: 44 | msg.remove(line) 45 | except: 46 | pass 47 | return msg 48 | 49 | #print remaining_msg(body, fetched) 50 | print remaining_msg(b2, f2) 51 | #print fetched[3] in body 52 | -------------------------------------------------------------------------------- /KS/info.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/info.pyc -------------------------------------------------------------------------------- /KS/info_states/dict.py: -------------------------------------------------------------------------------- 1 | us_states = ['WA', 'Washington', 'WI', 'Wisconsin', 2 | 'WV', 'West Virginia', 'FL', 3 | 'Florida', 'WY', 'Wyoming', 'NH', 4 | 'New Hampshire', 'NJ', 'New Jersey', 5 | 'NM', 'New Mexico', 'NA', 6 | 'National', 'NC', 'North Carolina', 7 | 'ND', 'North Dakota', 'NE', 8 | 'Nebraska', 'NY', 'New York', 'RI', 9 | 'Rhode Island', 'NV', 'Nevada', 10 | 'GU', 'Guam', 'CO', 'Colorado', 11 | 'CA', 'California', 'GA', 'Georgia', 12 | 'CT', 'Connecticut', 'OK', 13 | 'Oklahoma', 'OH', 'Ohio', 'KS', 14 | 'Kansas', 'SC', 'South Carolina', 15 | 'KY', 'Kentucky', 'OR', 'Oregon', 16 | 'SD', 'South Dakota', 'DE', 17 | 'Delaware', 'DC', 18 | 'District of Columbia', 'HI', 19 | 'Hawaii', 'PR', 'Puerto Rico', 'TX', 20 | 'Texas', 'LA', 'Louisiana', 'TN', 21 | 'Tennessee', 'PA', 'Pennsylvania', 22 | 'VA', 'Virginia', 'VI', 23 | 'Virgin Islands', 'AK', 'Alaska', 24 | 'AL', 'Alabama', 'AS', 25 | 'American Samoa', 'AR', 'Arkansas', 26 | 'VT', 'Vermont', 'IL', 'Illinois', 27 | 'IN', 'Indiana', 'IA', 'Iowa', 'AZ', 28 | 'Arizona', 'ID', 'Idaho', 'ME', 29 | 'Maine', 'MD', 'Maryland', 'MA', 30 | 'Massachusetts', 'UT', 'Utah', 'MO', 31 | 'Missouri', 'MN', 'Minnesota', 'MI', 32 | 'Michigan', 'MT', 'Montana', 'MP', 33 | 'Northern Mariana Islands', 'MS', 34 | 'Mississippi' 35 | ] 36 | 37 | print len(us_states) 38 | 39 | 40 | -------------------------------------------------------------------------------- /KS/main_app_dol.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/main_app_dol.zip -------------------------------------------------------------------------------- /KS/modified.py: -------------------------------------------------------------------------------- 1 | #Reading inbox emails from CLI. 2 | #!/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | 9 | # some datas to initialize with 10 | imaplib._MAXLINE = 400000 11 | 12 | ORG_EMAIL = "@gmail.com" 13 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 14 | FROM_PWD = getpass.getpass() 15 | SMTP_SERVER = "imap.gmail.com" # varies depending on the imap server 16 | SMTP_PORT = 993 17 | 18 | # mail = imaplib.IMAP4_SSL(SMTP_SERVER) 19 | # mail.login(FROM_EMAIL, FROM_PWD) 20 | # mail.list() 21 | # mail.select('inbox') 22 | 23 | i = 0 24 | 25 | def main(): 26 | global i 27 | clear() 28 | # login 29 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) 30 | mail.login(FROM_EMAIL, FROM_PWD) 31 | mail.list() 32 | mail.select('inbox') 33 | inp = 'n' 34 | 35 | # start fetching mails one by one 36 | while(inp!='q'): 37 | print('Fetching mails. Please wait...') 38 | if inp == 'n': 39 | i += 1 40 | elif inp == 'p' and i != 1: 41 | i -= 1 42 | else: 43 | print('Please enter valid input.') 44 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 45 | latest_email_uid = data[0].split()[-i] # fetch mails 46 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') 47 | raw_email = data[0][1] 48 | email_message = email.message_from_string(raw_email) 49 | 50 | clear() # clear screen and print mail 51 | print 'To:', email_message['To'] 52 | print 'Sent from:', email_message['From'] 53 | print 'Date:', email_message['Date'] 54 | print 'Subject:', email_message['Subject'] 55 | print '*'*30, 'MESSAGE', '*'*30 56 | maintype = email_message.get_content_maintype() 57 | #print maintype 58 | 59 | if maintype == 'multipart': # get the body of the mail 60 | print email_message.get_payload()[0].get_payload() # to get the plain text only 61 | elif maintype == 'text': 62 | line = email_message.get_payload()[ 0 ] 63 | print line 64 | print '*'*69 65 | welcome() 66 | inp = raw_input('>> Enter your choice: ').lower() 67 | 68 | 69 | 70 | def clear(): 71 | os.system('cls' if os.name == 'nt' else 'clear') 72 | 73 | def welcome(): 74 | print '\n' 75 | print '>> Enter \'n\' to check NEXT mail' 76 | print '>> Enter \'p\' to check PREVIOUS mail' 77 | print '>> Enter \'q\' to QUIT' 78 | 79 | if __name__ == '__main__': 80 | main() 81 | -------------------------------------------------------------------------------- /KS/name.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/name.pyc -------------------------------------------------------------------------------- /KS/new.py: -------------------------------------------------------------------------------- 1 | #Read your inbox email and automate the boring stuff. 2 | #!/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | 5 | import base64, imaplib, email, re, os 6 | import getpass 7 | from bs4 import BeautifulSoup 8 | imaplib._MAXLINE = 400000 9 | 10 | ORG_EMAIL = "@gmail.com" 11 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 12 | FROM_PWD = getpass.getpass() 13 | SMTP_SERVER = "imap.gmail.com" 14 | SMTP_PORT = 993 15 | 16 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) 17 | mail.login(FROM_EMAIL, FROM_PWD) 18 | mail.list() 19 | mail.select('inbox') 20 | 21 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 22 | latest_email_uid = data[0].split()[-1] 23 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') 24 | raw_email = data[0][1] 25 | 26 | #### parsing email 27 | 28 | email_message = email.message_from_string(raw_email) 29 | print 'To:', email_message['To'] 30 | print 'Sent from:', email_message['From'] 31 | print 'Date:', email_message['Date'] 32 | print 'Subject:', email_message['Subject'] 33 | print '*'*30, 'MESSAGE', '*'*30 34 | maintype = email_message.get_content_maintype() 35 | #print maintype 36 | 37 | if maintype == 'multipart': 38 | for part in email_message.get_payload(): 39 | if part.get_content_maintype() == 'text': 40 | print part.get_payload() 41 | elif maintype == 'text': 42 | print email_message.get_payload() 43 | print '*'*69 44 | 45 | -------------------------------------------------------------------------------- /KS/new_app/address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import pyap 4 | 5 | test_address = """ 6 | David, 7 | 8 | We need a witness statement for one of our files. Please see below for 9 | the list of questions. 10 | 11 | Witness name: Salina Ramos 12 | Phone: (818) 723-6578 13 | 14 | 15 | Sincerely, 16 | 17 | Jackie Levine 18 | Assistant to Kyle K. Madison 19 | 20 | 21 | 22 | 11111 Santa Monica Blvd, Suite 100 23 | Los Angeles, CA 90025 24 | (310) 201-7676 (Office) 25 | (310) 744-0111 (Fax) 26 | 27 | The information in this e-mail (including attachments, if any) is 28 | considered confidential and is intended only for the recipient(s) listed 29 | above. Any review, use, disclosure, distribution or copying of this e-mail 30 | is prohibited except by or on behalf of the intended recipient. If you 31 | have received this email in error, 32 | """ 33 | test = ''' 34 | Hi David, 35 | 36 | Please send someone to sign: 37 | 38 | Maria Reyes 39 | Ph: 909-246-5391 (SPANISH) 40 | Address: 4138 Mission Blvd Space 58, Montclair, CA 91763 41 | DOL 01/08/2018 42 | 43 | Thank you 44 | 45 | 46 | ''' 47 | t2 = ''' 48 | Hello Team, 49 | 50 | We have a family that was involved in a MVA and needs to be contacted to set up an appointment for tomorrow, clients prefer at 11:00 a.m. 51 | 52 | Here is the contact person/client and location of sign-up, please note adult clients areSpanish speaking only: 53 | 54 | Jose A. Rios 55 | *400 Palm Avenue* 56 | *Watsonville, CA 95076* 57 | (831) 234-3634 58 | 59 | Date of Accident: 12/17/17 60 | 61 | Clients: 62 | 63 | 1. Juan R. Vega – driver 64 | 2. Jose A. Rios – passenger & vehicle owner 65 | 3. Enriqueta Rios – passenger & wife to Jose Rios 66 | 4. Elizabeth Rios – passenger & daughter to Jose Rios [she has down syndrome, Jose Rios will be her legal guardian and will answer questions on her behalf] 67 | 5. Roxanna Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 68 | 6. Iliana Rios – passenger & granddaughter to Jose Rios [she is a minor, Pedro Rios is the father] 69 | 70 | All adult clients will be at the above address, we are waiting to confirm if the father of both minors will be present, if not a separate meeting will be necessary. 71 | 72 | ''' 73 | t3 = ''' 74 | Jose A. Rios 75 | *400 Palm Avenue* 76 | *Watsonville, CA 95076* 77 | ''' 78 | def preprocess(arr_body): 79 | new_arr = [] 80 | for line in arr_body: 81 | line = line.replace('*', '') 82 | new_arr.append(line) 83 | return new_arr 84 | 85 | def fetch_address(arr_body): 86 | msg_body = preprocess(arr_body) 87 | msg_body = '\n'.join(msg_body) 88 | # print msg_body 89 | addresses = pyap.parse(msg_body, country='US') 90 | location = [] 91 | try: 92 | for address in addresses: 93 | # shows found address 94 | location.append(address) 95 | # print address 96 | except: 97 | pass 98 | return location 99 | 100 | #print(address.as_dict()) 101 | # print fetch_address(t3) 102 | -------------------------------------------------------------------------------- /KS/new_app/info.py: -------------------------------------------------------------------------------- 1 | us_states = ['WA', 'Washington', 'WI', 'Wisconsin', 2 | 'WV', 'West Virginia', 'FL', 3 | 'Florida', 'WY', 'Wyoming', 'NH', 4 | 'New Hampshire', 'NJ', 'New Jersey', 5 | 'NM', 'New Mexico', 'NA', 6 | 'NC', 'North Carolina', 7 | 'ND', 'North Dakota', 'NE', 8 | 'Nebraska', 'NY', 'New York', 'RI', 9 | 'Rhode Island', 'NV', 'Nevada', 10 | 'GU', 'Guam', 'CO', 'Colorado', 11 | 'CA', 'California', 'GA', 'Georgia', 12 | 'CT', 'Connecticut', 'OK', 13 | 'Oklahoma', 'OH', 'Ohio', 'KS', 14 | 'Kansas', 'SC', 'South Carolina', 15 | 'KY', 'Kentucky', 'OR', 'Oregon', 16 | 'SD', 'South Dakota', 'DE', 17 | 'Delaware', 'DC', 18 | 'District of Columbia', 'HI', 19 | 'Hawaii', 'PR', 'Puerto Rico', 'TX', 20 | 'Texas', 'LA', 'Louisiana', 'TN', 21 | 'Tennessee', 'PA', 'Pennsylvania', 22 | 'VA', 'Virginia', 'VI', 23 | 'Virgin Islands', 'AK', 'Alaska', 24 | 'AL', 'Alabama', 'AS', 25 | 'American Samoa', 'AR', 'Arkansas', 26 | 'VT', 'Vermont', 'IL', 'Illinois', 27 | 'IN', 'Indiana', 'IA', 'Iowa', 'AZ', 28 | 'Arizona', 'ID', 'Idaho', 'ME', 29 | 'Maine', 'MD', 'Maryland', 'MA', 30 | 'Massachusetts', 'UT', 'Utah', 'MO', 31 | 'Missouri', 'MN', 'Minnesota', 'MI', 32 | 'Michigan', 'MT', 'Montana', 'MP', 33 | 'Northern Mariana Islands', 'MS', 34 | 'Mississippi' 35 | ] 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /KS/new_app/name.py: -------------------------------------------------------------------------------- 1 | import re 2 | import nltk 3 | from nltk.corpus import stopwords 4 | stop = stopwords.words('english') 5 | 6 | document=""" 7 | David, 8 | 9 | I need this signed up ASAP in Santa Cruz. Brain injury. Wi 10 | 11 | Joshua Orosco 12 | Tel#: 831-201 7096 13 | 14 | Needs a call right now to schedule time and location 15 | 16 | Reza 17 | 18 | 19 | -- 20 | Reza Torkzadeh 21 | Office: 888.222.8286 22 | Mobile: 949.698.8087 23 | 24 | Please note: This message is being sent via mobile phone. Please excuse any informalities, brevity, spelling and grammatical errors. 25 | """ 26 | check = ['Annette Anderson,', 27 | 'The client is a referral from our chiro- she is there now about to have her', 28 | 'appointment. Please reach out in the next hour!', 'Respectfully,'] 29 | 30 | def extract_names(document): 31 | '''takes a string input and 32 | print a set of all the names present in it 33 | ''' 34 | document = '\n'.join(document) 35 | #print document 36 | document = ' '.join([i for i in document.split() if i not in stop]) 37 | sentences = nltk.sent_tokenize(document) 38 | sentences = [nltk.word_tokenize(sent) for sent in sentences] 39 | sentences = [nltk.pos_tag(sent) for sent in sentences] 40 | names = [] 41 | for tagged_sentence in sentences: 42 | for chunk in nltk.ne_chunk(tagged_sentence): 43 | if type(chunk) == nltk.tree.Tree: 44 | if chunk.label() == 'PERSON': 45 | names.append(' '.join([c[0] for c in chunk])) 46 | 47 | 48 | names_unique=set(names) 49 | # print(names_unique) 50 | my_list = list(name.upper() for name in names_unique) 51 | return my_list 52 | 53 | #print extract_names(check) 54 | -------------------------------------------------------------------------------- /KS/new_app/new_app.py: -------------------------------------------------------------------------------- 1 | # Reading inbox emails from CLI. 2 | # !/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | 9 | from info import us_states as states 10 | from address import fetch_address 11 | from name import extract_names 12 | from remove_sig import remove_signature 13 | 14 | 15 | # some required datas to initialize with 16 | imaplib._MAXLINE = 400000 17 | 18 | ORG_EMAIL = "@gmail.com" 19 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 20 | FROM_PWD = getpass.getpass() 21 | SMTP_SERVER = "imap.gmail.com" # varies depending on the imap server 22 | SMTP_PORT = 993 23 | 24 | i = 0 25 | body_fetched = [] # to contain all the lines which has been printed already 26 | 27 | 28 | def main(): 29 | global i, body_fetched, email_message 30 | clear() 31 | # login 32 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) 33 | mail.login(FROM_EMAIL, FROM_PWD) 34 | mail.list() 35 | mail.select('inbox') 36 | inp = 'n' 37 | 38 | # start fetching mails one by one 39 | while (inp != 'q'): 40 | print('Fetching mails. Please wait...') 41 | if inp == 'n': 42 | i += 1 43 | elif inp == 'p' and i != 1: 44 | i -= 1 45 | else: 46 | print('Please enter valid input.') 47 | 48 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 49 | latest_email_uid = data[0].split()[-i] # fetch mails 50 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') 51 | raw_email = data[0][1] 52 | email_message = email.message_from_string(raw_email) 53 | 54 | clear() # clear screen and print mail 55 | print 'To:', email_message['To'] 56 | print 'Sent from:', email_message['From'] 57 | print 'Date:', email_message['Date'] 58 | print 'Subject:', email_message['Subject'] 59 | print '\n' 60 | maintype = email_message.get_content_maintype() 61 | 62 | if maintype == 'multipart': # get the body of the mail 63 | body = email_message.get_payload()[0].get_payload() # to get the plain text only 64 | elif maintype == 'text': 65 | body = email_message.get_payload()[0] 66 | 67 | # print body.split('\n') 68 | # preprocessing the body to remove signature 69 | body = remove_signature(body) 70 | # print body 71 | body_fetched = [] 72 | 73 | dols = extract_dol(body) 74 | phone_no = get_phoneNumber(body) 75 | 76 | # adding the two items in the fetched list 77 | body_fetched.extend(phone_no.split('\n')) 78 | body_fetched.extend(dols) 79 | 80 | # print body_fetched 81 | print 'Phone Number: ', phone_no 82 | 83 | # print body_fetched 84 | 85 | for dol in dols: 86 | print str(dol) 87 | 88 | print '\n' 89 | # print body_fetched 90 | remaining_body_location = remaining_msg(body.split('\n'), body_fetched) 91 | # print remaining_body_location 92 | 93 | location = fetch_address(remaining_body_location) 94 | 95 | if len(location) != 0: 96 | for address in location: 97 | body_fetched.append(str(address)) 98 | print 'Address: ', address 99 | else: 100 | loc = location_fetch(remaining_body_location) 101 | body_fetched.append(str(loc)) 102 | loc = loc.split() 103 | new_locs = [] 104 | for lo in loc: 105 | if 'ADDRESS' not in lo.upper(): 106 | new_locs.append(lo) 107 | # print 'didn\'t work' 108 | print 'Address: ', ' '.join(new_locs) 109 | 110 | # print 'fetched ', body_fetched 111 | remaining_body_name = remaining_msg(remaining_body_location, body_fetched) 112 | # print 'name ', remaining_body_name 113 | names = extract_names(remaining_body_name) 114 | 115 | print '\n' 116 | 117 | # if first line contains DAVID ignore it. 118 | print 'Name: ', 119 | if len(remaining_body_name) != 0: 120 | if 'DAVID' in remaining_body_name[0].upper(): 121 | names.remove('DAVID') 122 | for j in range(len(names)): 123 | print names[j] 124 | 125 | # print '*'*69 126 | welcome() 127 | inp = raw_input('>> Enter your choice: ').lower() 128 | 129 | 130 | # extract DOLs 131 | def extract_dol(body): 132 | '''splitting the message into lines 133 | and extracting the lines with DOL in it 134 | ''' 135 | 136 | dol_matches = ['DOL', 'DATE OF LOSS', 'DATE OF ACCIDENT'] 137 | body = body.split('\n') 138 | dol_arr = [] 139 | for line in body: 140 | for dol in dol_matches: 141 | if dol in line.upper(): 142 | dol_arr.append(line) 143 | return dol_arr 144 | 145 | 146 | # extract phone no using regex 147 | def get_phoneNumber(text): 148 | ''' Matches 3334445555, 333.444.5555, 333-444-5555, 149 | 333 444 5555, (333) 444 5555 and all combinations thereof, 150 | like 333 4445555, (333)4445555 or 333444-5555. 151 | Does not match international notation +13334445555, 152 | but matches domestic part in +1 333 4445555. 153 | using regex for extracting phone numbers 154 | then pass that compiled regex to get_phoneNumbers 155 | function and returns a string of phone numbers 156 | present in the text 157 | ''' 158 | 159 | phone_number = "" 160 | regex = re.compile(r"\(?\b[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}\b") 161 | for phoneNumber in get_phoneNumbers(text, regex): 162 | phone_number = phone_number + phoneNumber + "\n" 163 | return phone_number 164 | 165 | 166 | def get_phoneNumbers(s, regex): 167 | ''' returns all the phone numbers present 168 | in the input string 169 | ''' 170 | 171 | return (phoneNumber for phoneNumber in re.findall(regex, s)) 172 | 173 | 174 | def remaining_msg(msg, fetched): 175 | '''to return a list of the message 176 | lines that hasn't been printed yetq 177 | ''' 178 | 179 | # msg = msg.split('\n') 180 | remains = [] # to contain the remaining body 181 | # print remains 182 | try: 183 | msg = [x.strip() for x in msg] 184 | fetched = [x.strip() for x in fetched] 185 | msg = list(filter(lambda a: a != '', msg)) 186 | fetched = list(filter(lambda a: a != '', fetched)) 187 | except: 188 | msg = [str(x) for x in msg] 189 | fetched = [str(x) for x in fetched] 190 | msg = list(filter(lambda a: a != '\r', msg)) 191 | fetched = list(filter(lambda a: a != '\r', fetched)) 192 | 193 | # print 'fetched ', fetched 194 | for fline in fetched: 195 | for line in msg: 196 | try: 197 | if line.find(fline) != -1: 198 | remains.append(line) 199 | break 200 | except: 201 | pass 202 | 203 | for line in msg: 204 | for fline in fetched: 205 | try: 206 | if fline.find(line) != -1: 207 | # print 'line: ', line 208 | remains.append(line) 209 | break 210 | except: 211 | pass 212 | 213 | #print remains 214 | #print '\n', msg 215 | for line in remains: 216 | try: 217 | msg.remove(line) 218 | except: 219 | pass 220 | return msg 221 | 222 | 223 | def location_fetch(msg): 224 | ''' the location ends with either state name or PIN 225 | using that this function checks for the words in each line 226 | if it contains the state then it will return the line 227 | ''' 228 | locs = [] 229 | for line in msg: 230 | linen = line.upper() 231 | if linen.find('ADDRESS') != -1: 232 | locs.append(line) 233 | break 234 | for line in msg: 235 | words = line.split() 236 | for word in words: 237 | if word in states: 238 | locs.append(line) 239 | return ' '.join(locs) 240 | 241 | 242 | def clear(): 243 | os.system('cls' if os.name == 'nt' else 'clear') 244 | 245 | 246 | def welcome(): 247 | print '\n' 248 | print '>> Enter \'n\' to check NEXT mail' 249 | print '>> Enter \'p\' to check PREVIOUS mail' 250 | print '>> Enter \'q\' to QUIT' 251 | 252 | 253 | if __name__ == '__main__': 254 | main() 255 | -------------------------------------------------------------------------------- /KS/new_app/remove_sig.py: -------------------------------------------------------------------------------- 1 | import talon 2 | from talon import signature as sig 3 | from talon.signature.bruteforce import extract_signature 4 | # don't forget to init the library first 5 | # it loads machine learning classifiers 6 | talon.init() 7 | 8 | 9 | text1 = '''(818) 212-8948 10 | DOL: 10/20/2017 & DOL: 6/2017 11 | 10906 Woodley Ave Granada Hills CA 12 | Client has two cases to sign 13 | 14 | -- 15 | Leslie Garcia, Intake Coordinator 16 | Akiva Niamehr LLP 17 | 10900 Wilshire Blvd. Ste. 930 | Los Angeles, CA 90024 18 | P: 424.653.1093 | F: 310.882.5444 19 | E: leslie@anattorneys.com 20 | ''' 21 | text3 = ''' 22 | Hi David, 23 | 24 | 25 | 26 | We need a witness statement for one of our files. Please see below for 27 | 28 | the list of questions. 29 | 30 | 31 | 32 | Witness name: Salina Ramos 33 | 34 | Phone: (818) 723-6578 35 | 36 | 37 | 38 | 39 | -- 40 | Abhinav Anand, 41 | +91 8461077468 42 | ABV-IIITM, GWALIOR, MP, 474015 43 | ''' 44 | text2 = """Annette Anderson, 45 | 11833 Spring Laurel DR 46 | Charlotte, NC 28215 47 | 704-724-4697 48 | 49 | Client is a referral from our chiro- she is there now about to have her appointment. Please reach out in the next hour! 50 | 51 | Respectfully, 52 | 53 | Lacie N. Johnson 54 | Intake Paralegal 55 | Law Offices of Shane Smith, PC 56 | 263 Hwy 74 N 57 | Peachtree City, GA 30269 58 | 59 | 770.487.8999 ext. 42 60 | 770.631.7667 fax 61 | """ 62 | def remove_signature(message): 63 | msge = message.split('\n') 64 | # msg = list(filter(lambda a: a != '', msg)) 65 | # msg = list(filter(lambda a: a != ' ', msg)) 66 | # print msg 67 | try: 68 | msg = [x.rstrip() for x in msge] 69 | except: 70 | pass 71 | message = '\n'.join(msg) 72 | if '--' in msg: 73 | text, signature = extract_signature(message) 74 | else: 75 | text, signature = sig.extract(message, sender='john.doe@example.com') 76 | 77 | return text 78 | 79 | 80 | # print remove_signature(text1) 81 | # print '\n\n' 82 | # print remove_signature(text3) 83 | -------------------------------------------------------------------------------- /KS/new_app_2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/new_app_2.zip -------------------------------------------------------------------------------- /KS/phoneno.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def get_phoneNumber(text): 4 | phone_number = "" 5 | regex = re.compile(r"\(?\b[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}\b") 6 | for phoneNumber in get_phoneNumbers(text, regex): 7 | phone_number = phone_number + phoneNumber + "\n" 8 | return phone_number 9 | 10 | def get_phoneNumbers(s, regex): 11 | return (phoneNumber for phoneNumber in re.findall(regex, s)) 12 | 13 | text = ''' 14 | (818) 212-8948 15 | DOL: 10/20/2017 & DOL: 6/2017 16 | 10906 woodley ava granada hills CA 17 | (818) 212-8999 18 | Client has two cases to sign 19 | ''' 20 | print get_phoneNumber(text) 21 | -------------------------------------------------------------------------------- /KS/problem.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/problem.PNG -------------------------------------------------------------------------------- /KS/remove_sig.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/remove_sig.pyc -------------------------------------------------------------------------------- /KS/test case.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/KS/test case.docx -------------------------------------------------------------------------------- /KS/unwanted_names.py: -------------------------------------------------------------------------------- 1 | unwanted = [ 2 | 'THANKS', 3 | 'THANK', 4 | 'PLEASE', 5 | 'SORRY', 6 | 'INTAKES', 7 | 'INTAKE', 8 | 'HELLO' 9 | ] 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Automating It! 2 | [![Build Status](https://travis-ci.org/arpitx165/Automation-Bots.svg?branch=master)](https://travis-ci.org/arpitx165/Automation-Bots) 3 | 4 | 5 | 6 | ## View the demo of the bots here at this channel 7 | [Bots | Youtube](https://www.youtube.com/channel/UCJPR7NC5igzhgzjRFeNWLvQ) 8 | 9 | ## Details 10 | 11 | - cleverbot.py 12 | 13 | - [x] A chatbot created using cleverbot API. 14 | 15 | - full-contact.py 16 | 17 | - [x] Takes email ID as input and provides information like Full name, address, etc., using FullContact API. 18 | 19 | - ipl.py 20 | 21 | - [x] Get the ipl updates at every 30 seconds. 22 | 23 | - quora.py 24 | 25 | - [x] It enables you to use quora from cmd/terminal/shell. It will ask you to enter any question that you need to search on quora, then according to that it will search some(8-10) relevant questions from which you can select a question and after that it will give you an answer of that question. Lastly it'll ask you whether you want more answers(y/n), if you choose 'y' then it'll redirect you to that Quora page where the question and its answers are present. 26 | 27 | - wolfram_bot.py 28 | 29 | - [x] Wolfram Alpha is an online service that answers factual queries directly by computing the answer from externally sourced "curated data". 30 | Using it's API, this provides various no. of services. 31 | 32 | - youtube.py 33 | 34 | - [x] The program takes name of a song then it will open your default web-browser and it will play that song on youtube. 35 | 36 | - kiara.py 37 | 38 | - [x] A mini digital assistant to which can give you information like general questions, weather news, math, and wikipedia info of that topic. 39 | It has Text-To-Speech feature. 40 | 41 | - loremipsum.py 42 | 43 | - [x] Generate one paragraph of short lorem ipsum using loripsum.net API. 44 | 45 | - youtubecrawl.py 46 | 47 | - [x] This is a python script which lets the user download the mp3 type audio file of any video of youtube. It also gives the user an option to download the lyrics in a text file if the video is a song. It makes it very easy for the user to download a video/song of his choice as it just asks the user to enter the name of the video.The results get better and more precise if the user specifies the name of the artist as well. 48 | 49 | - earthquake.py 50 | 51 | - [x] Monitoring earthquakes around the planet using data from [https://earthquake.usgs.gov/](https://earthquake.usgs.gov/). 52 | - googletranslate.py 53 | 54 | - [x] The script can translate words via Google Translate between different languages. The detailed usage can be found by running the following command: 55 | `python googletranslate.py -h` 56 | 57 | - codechef_submission.py 58 | 59 | - [x] An automated codechef submission tool using selenium webdriver. Just provide problem code and name of your submission file and get result of your submission in terminal itself. 60 | 61 | 62 | - Codechef automation bot 63 | 64 | - [x] This is a bot used for downloading the testcases from codechef contests and testing them against given testcases and submiting the solutions all done in command line *(for more details checkout the 'README.md' file in 'Codechef _automation_bot' folder).* 65 | - [x] To checkout this repo use [this link](https://github.com/parikshith19/codechef_automation_bot). 66 | - worldtime.py 67 | 68 | - [x] A terminal tool to check the time of anywhere. 69 | 70 | - [x] Usage: `python worldtime.py -l ` 71 | 72 | - [x] i.e.: `python worldtime.py -l London`, the output will be `London, United Kingdom 2017-10-04 01:27:46` 73 | 74 | - wiki-crawler.py 75 | 76 | - [x] A web crawler that you feed a starting article and an ending article. The crawler then follows article links until it finds your ending article. 77 | 78 | - pokeapi.py 79 | 80 | - [x] Script that consumes the [Pokéapi](https://pokeapi.co/) and returns pokémon info. 81 | 82 | - [x] Usage: `python pokeapi.py` 83 | 84 | - exchange_rates.py 85 | 86 | - [x] You enter a currency code and get actual information about the currency exchange rates. 87 | 88 | - Email Parsing 89 | - [x] An email parsing tool right from the CLI 90 | 91 | - vurl.py 92 | - [x] Tool that shorten links using the vurl api. 93 | - [x] Usage: `python vurl.py [-h] -l LINKS [LINKS ...]` 94 | 95 | - youtubeTrailers.py 96 | 97 | - [x] Automated script that fetches you latest trailers of movies from youtube. For example trailers of English movies. 98 | - [x] Usage: `python youtubeTrailers.py ` 99 | 100 | - fakeuser.py 101 | - [x] Tool that returns random fake profile data. 102 | - [x] Usage: `python fakeuser.py` 103 | 104 | - clap_activated_switch_arduino 105 | - [x] Automation mean simplifying human life. This file can be burn in Arduino and you can control any one electrical device with your clap. 106 | 107 | 108 | Note - 109 | 110 | 1. The codes uses an API key which has been deactivated so you will need to get your own. 111 | Before running the programs make sure you have installed the libraries or modules. 112 | 113 | 2. For contributions check [here](CONTRIBUTING.md) 114 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | # Reading inbox emails from CLI. 2 | # !/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | from info import us_states as states 9 | 10 | # some required datas to initialize with 11 | imaplib._MAXLINE = 400000 12 | 13 | ORG_EMAIL = "@gmail.com" 14 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 15 | FROM_PWD = getpass.getpass() 16 | SMTP_SERVER = "imap.gmail.com" # varies depending on the imap server 17 | SMTP_PORT = 993 18 | 19 | i = 0 20 | 21 | def main(): 22 | global i 23 | clear() 24 | # login 25 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) 26 | mail.login(FROM_EMAIL, FROM_PWD) 27 | mail.list() 28 | mail.select('inbox') 29 | inp = 'n' 30 | 31 | # start fetching mails one by one 32 | while(inp!='q'): 33 | print('Fetching mails. Please wait...') 34 | if inp == 'n': 35 | i += 1 36 | elif inp == 'p' and i != 1: 37 | i -= 1 38 | else: 39 | print('Please enter valid input.') 40 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 41 | latest_email_uid = data[0].split()[-i] # fetch mails 42 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') 43 | raw_email = data[0][1] 44 | email_message = email.message_from_string(raw_email) 45 | 46 | clear() # clear screen and print mail 47 | print 'To:', email_message['To'] 48 | print 'Sent from:', email_message['From'] 49 | print 'Date:', email_message['Date'] 50 | print 'Subject:', email_message['Subject'] 51 | #print '*'*30, 'MESSAGE', '*'*30 52 | print '\n' 53 | maintype = email_message.get_content_maintype() 54 | #print maintype 55 | 56 | if maintype == 'multipart': # get the body of the mail 57 | body = email_message.get_payload()[0].get_payload() # to get the plain text only 58 | dols = extract_dol(body) 59 | phone_no = get_phoneNumber(body) 60 | 61 | print 'Phone Number: ', phone_no 62 | 63 | # remain = remaining_msg(body, phone_no, dols) 64 | loc = location(body) 65 | 66 | for dol in dols: 67 | print str(dol) 68 | 69 | print '\n' 70 | 71 | print 'Location: ',str(loc) 72 | 73 | elif maintype == 'text': 74 | line = email_message.get_payload()[ 0 ] 75 | dols = extract_dol(line) 76 | phone_no = get_phoneNumber(line) 77 | print 'Phone Number: ', phone_no 78 | remain = remaining_msg(line, phone_no, dols) 79 | 80 | for dol in dols: 81 | print str(dol) 82 | 83 | print '\n' 84 | 85 | for re in remain: 86 | print str(re) 87 | # print '*'*69 88 | welcome() 89 | inp = raw_input('>> Enter your choice: ').lower() 90 | 91 | # extract DOLs 92 | def extract_dol(string): 93 | ''' splitting the message into lines 94 | and extracting the lines with DOL in it ''' 95 | string = string.split('\n') 96 | dol_arr = [] 97 | for text in string: 98 | if "DOL" in text: 99 | dol_arr.append(text) 100 | return dol_arr 101 | 102 | 103 | # extract phone no using regex 104 | def get_phoneNumber(text): 105 | ''' Matches 3334445555, 333.444.5555, 333-444-5555, 106 | 333 444 5555, (333) 444 5555 and all combinations thereof, 107 | like 333 4445555, (333)4445555 or 333444-5555. 108 | Does not match international notation +13334445555, 109 | but matches domestic part in +1 333 4445555. 110 | using regex for extracting phone numbers 111 | then pass that compiled regex to get_phoneNumbers 112 | function and returns a string of phone numbers 113 | present in the text ''' 114 | phone_number = "" 115 | regex = re.compile(r"\(?\b[2-9][0-9]{2}\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}\b") 116 | for phoneNumber in get_phoneNumbers(text, regex): 117 | phone_number = phone_number + phoneNumber + "\n" 118 | return phone_number 119 | 120 | def get_phoneNumbers(s, regex): 121 | ''' returns all the phone numbers present 122 | in the input string ''' 123 | return (phoneNumber for phoneNumber in re.findall(regex, s)) 124 | 125 | def remaining_msg(msg, phone_no, dol): 126 | ''' with a purpose of fetching location 127 | we simply return whatever is remained in 128 | the message body''' 129 | msg = msg.split('\n') 130 | phone_no = phone_no.split() 131 | exclude = [] 132 | for line in msg: 133 | for no in phone_no: 134 | if no in line: 135 | exclude.append(line) 136 | dol = [str(a) for a in dol] 137 | exclude.extend(dol) 138 | return [remain for remain in msg if remain not in exclude] 139 | 140 | def location(msg): 141 | ''' the location ends with either state name or PIN 142 | using that this function checks for the words in each line 143 | if it contains the state then it will return the line''' 144 | msg = msg.split('\n') 145 | for line in msg: 146 | words = line.split() 147 | for word in words: 148 | if word in states: 149 | return line 150 | 151 | def clear(): 152 | os.system('cls' if os.name == 'nt' else 'clear') 153 | 154 | def welcome(): 155 | print '\n' 156 | print '>> Enter \'n\' to check NEXT mail' 157 | print '>> Enter \'p\' to check PREVIOUS mail' 158 | print '>> Enter \'q\' to QUIT' 159 | 160 | if __name__ == '__main__': 161 | main() 162 | -------------------------------------------------------------------------------- /clap_activated_switch_arduino: -------------------------------------------------------------------------------- 1 | //single clap activated switch using arduino. 2 | const int micPin = 3; 3 | const int ledPin = 4; 4 | 5 | 6 | int micState = 0; 7 | int var = 1; 8 | 9 | void setup() { 10 | 11 | pinMode(ledPin, OUTPUT); 12 | 13 | pinMode(micPin, INPUT); 14 | } 15 | 16 | void loop() { 17 | 18 | micState = digitalRead(micPin); 19 | 20 | if (micState == HIGH) { 21 | var=var+1; 22 | delay(500);De 23 | } 24 | else { 25 | var=var; 26 | } 27 | if (var%2==1){ 28 | 29 | digitalWrite(ledPin, HIGH); 30 | 31 | } 32 | else { 33 | 34 | digitalWrite(ledPin, LOW); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /cleverbot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | from cleverwrap import CleverWrap 3 | import pyttsx 4 | import os 5 | os.environ["HTTPS_PROXY"] = "http://usr_name:pass@proxy:port" 6 | 7 | cw = CleverWrap("API_KEY") 8 | 9 | 10 | a='y' 11 | engine = pyttsx.init() 12 | voices = engine.getProperty('voices') 13 | engine.setProperty('voice', voices[4].id) 14 | rate = engine.getProperty('rate') 15 | engine.setProperty('rate', rate-30) 16 | engine.say('Hellllllo there. I\'m scarlett') 17 | engine.runAndWait() 18 | while a is not 'n': 19 | 20 | ans=cw.say(raw_input('You: ')) 21 | print 'Kiara: '+ans 22 | engine.say(ans) 23 | engine.runAndWait() 24 | 25 | #a=raw_input('wanna chat more(y/n): ') 26 | 27 | cw.reset() 28 | -------------------------------------------------------------------------------- /codechef_submission.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import getpass 3 | import time 4 | 5 | # codechef credentials for login 6 | username = "nikhilksingh97" 7 | password = getpass.getpass("Password: ") 8 | 9 | # problem code 10 | problem = input("Problem code: ") 11 | 12 | # submission code 13 | submission_file = input("Submission file: ") 14 | 15 | with open(submission_file, 'r') as f: 16 | code = f.read() 17 | 18 | # start a browser session 19 | browser = webdriver.Firefox() 20 | 21 | # open link in browser 22 | browser.get('https://www.codechef.com') 23 | 24 | # login 25 | nameElem = browser.find_element_by_id('edit-name') 26 | nameElem.send_keys(username) 27 | 28 | passElem = browser.find_element_by_id('edit-pass') 29 | passElem.send_keys(password) 30 | 31 | browser.find_element_by_id('edit-submit').click() 32 | 33 | # open submission page 34 | browser.get("https://www.codechef.com/submit/" + problem) 35 | 36 | # sleep function to let web components load in case of slow internet connnection 37 | time.sleep(10) 38 | 39 | # click on toggle button to open simple text mode 40 | browser.find_element_by_id("edit_area_toggle_checkbox_edit-program").click() 41 | 42 | # submit the code 43 | inputElem = browser.find_element_by_id('edit-program') 44 | inputElem.send_keys(code) 45 | 46 | browser.find_element_by_id("edit-submit").click() 47 | 48 | # get result 49 | result = browser.find_element_by_id("display_result").text 50 | 51 | print(result) 52 | -------------------------------------------------------------------------------- /earthquake.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | import datetime 4 | import requests 5 | import json 6 | from colorama import Fore, init 7 | 8 | URL = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson" 9 | UPDATES = [] 10 | 11 | def earthquake_print(data): 12 | for i in data['features']: 13 | if i['id'] not in UPDATES: 14 | UPDATES.append(i['id']) 15 | print('___________________________________________________________________________________________________') 16 | print(i['properties']['title'], end=' MAG: ') 17 | print(Fore.RED+str(i['properties']['mag'])) 18 | print('Location:', i['properties']['place']) 19 | alert = i['properties']['alert'] 20 | if alert == 'green': 21 | print(Fore.RED + 'Type: ' + i['properties']['type'], end=' ') 22 | elif alert == 'yellow': 23 | print(Fore.YELLOW + 'Type: ' + i['properties']['type'], end=' ') 24 | else: 25 | print(Fore.BLUE + 'Type: ' + i['properties']['type'], end=' ') 26 | ms = i['properties']['time'] 27 | print(datetime.datetime.fromtimestamp(ms/1000.0)) 28 | print('INFO:', i['properties']['url']) 29 | 30 | def get_earthquakes(): 31 | resp = requests.get(URL) 32 | resp = json.loads(resp.text) 33 | count = resp['metadata']['count'] 34 | if count != 0: 35 | earthquake_print(resp) 36 | else: 37 | pass 38 | 39 | if __name__ == '__main__': 40 | init(autoreset=True) 41 | if len(sys.argv) != 2: 42 | print('Usage: earthquake.py [time in seconds]') 43 | else: 44 | seconds = int(sys.argv[1]) 45 | while True: 46 | get_earthquakes() 47 | time.sleep(seconds) 48 | -------------------------------------------------------------------------------- /exchange_rates.py: -------------------------------------------------------------------------------- 1 | import urllib.request 2 | from datetime import datetime 3 | from bs4 import BeautifulSoup 4 | 5 | def get_page(url): 6 | return urllib.request.urlopen(url).read() 7 | 8 | 9 | def parse(html, currency): 10 | soup = BeautifulSoup(html, 'html.parser') 11 | table = soup.find('tbody') 12 | 13 | projects = [] 14 | 15 | 16 | 17 | for row in table.find_all('tr'): 18 | cols = row.find_all('td') 19 | 20 | projects.append( 21 | ' ' + 22 | cols[0].a.text + ' ' + 23 | cols[2].text + ' ' + 24 | cols[3].text) 25 | 26 | print('Currency code| Units per ' + currency + 27 | ' | ' + currency + ' per Unit' 28 | ' ') 29 | 30 | for project in projects: 31 | print(project) 32 | 33 | 34 | def main(): 35 | today_date = datetime.now().date() 36 | currency = input('Enter currency code (ex. USD): ') 37 | html = get_page('http://www.xe.com/currencytables/?from=' + currency + '&date=' + str(today_date)) 38 | parse(html, currency) 39 | 40 | 41 | if __name__ == '__main__': 42 | main() 43 | -------------------------------------------------------------------------------- /fakeuser.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | def fake_user(): 4 | r = requests.get('https://api.randomuser.me/') 5 | return r.json()['results'][0] 6 | 7 | def shows(r): 8 | print('Name:', r['name']['first'], r['name']['last']) 9 | print('Email:', r['email']) 10 | print('Username:', r['login']['username']) 11 | print('Password:', r['login']['password']) 12 | 13 | if __name__ == '__main__': 14 | r = fake_user() 15 | shows(r) 16 | -------------------------------------------------------------------------------- /full-contact.py: -------------------------------------------------------------------------------- 1 | from fullcontact import FullContact 2 | import json 3 | fc = FullContact('your_api_key') 4 | user_id = input('Please enter user email-id: ') 5 | r = fc.person(email=user_id) 6 | #data = json.load(r.json()) 7 | data = r.json() 8 | #print(data['contactInfo']) 9 | 10 | if data['status']==200: 11 | print('Name: '+data['contactInfo']['fullName']) 12 | print('Location: '+data['demographics']['locationDeduced']['deducedLocation']) 13 | else: 14 | print('Data unavailable right now.') 15 | -------------------------------------------------------------------------------- /googletranslate.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import requests 3 | import urllib 4 | import re 5 | 6 | # Declare source text, source language 7 | # and target language variables 8 | sourceText = "" 9 | sourceLang = "" 10 | targetLang = "" 11 | 12 | # Read command line arguments 13 | parser = argparse.ArgumentParser() 14 | parser.add_argument("-st", "--sourcetext", help="source text", type=str, metavar="") 15 | parser.add_argument("-sl", "--sourcelanguage", help="source language; Default value: auto", 16 | type=str, default="auto", metavar="") 17 | parser.add_argument("-tl", "--targetlanguage", help="target language; Default value: en", 18 | type=str, default="en", metavar="") 19 | args = parser.parse_args() 20 | sourceText = args.sourcetext.decode("utf8") 21 | sourceLang = args.sourcelanguage.decode("utf8") 22 | targetLang = args.targetlanguage.decode("utf8") 23 | 24 | # Invoke google translate 25 | url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" \ 26 | + sourceLang + "&tl=" + targetLang + "&dt=t&q=" + urllib.quote(sourceText.encode('utf8')) 27 | headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'} 28 | sc = requests.get(url, headers=headers) 29 | 30 | translatedText = re.findall(r'"([^"]*)"', sc.text)[0] 31 | print ("Source Text: " + sourceText) 32 | print ("Translation: " + translatedText) 33 | -------------------------------------------------------------------------------- /hiQ/bruno_mars.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | 4 | from bs4 import BeautifulSoup 5 | # uncomment the line below and set your user_id n pass if working on college proxy 6 | # os.environ["HTTPS_PROXY"] = "https://user_id:pass@192.168.1.107:3128" 7 | 8 | headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'} 9 | url='https://en.wikipedia.org/wiki/Bruno_Mars' 10 | 11 | source_code = requests.get(url, headers=headers, timeout=5) # get the raw code 12 | plain_text = source_code.content # convert into plain text 13 | soup = BeautifulSoup(plain_text,"html.parser") # convert to a bs4 object 14 | 15 | name = soup.find('h1',{'id':'firstHeading'}) 16 | nickname = soup.find('span',{'class':'nickname'}) 17 | print ('Name: {}'.format(name.get_text())) 18 | print ('Nickname: {}'.format(nickname.get_text())) 19 | paras = soup.find_all('p') 20 | print (paras[0].get_text()) 21 | -------------------------------------------------------------------------------- /hiQ/gaana.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | import webbrowser 4 | from bs4 import BeautifulSoup 5 | 6 | # uncomment the line below and set the user_id n pass if working on college proxy 7 | # os.environ["HTTPS_PROXY"] = "https://user_id:pass@192.168.1.107:3128" 8 | 9 | 10 | headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'} 11 | song_name_raw = input('Please enter a song name: ') 12 | song_name = song_name_raw.replace(' ', '%20') 13 | url = 'https://gaana.com/search/{}'.format(song_name) 14 | source_code = requests.get(url, headers=headers, timeout=5) 15 | plain_text = source_code.content 16 | soup = BeautifulSoup(plain_text,"html.parser") 17 | links = soup.find_all('a',{'class':'rt_arw'}) 18 | # print (links[0]['href']) 19 | webbrowser.open(links[0]['href']) 20 | 21 | 22 | -------------------------------------------------------------------------------- /ipl.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | import pyttsx 4 | import time 5 | from bs4 import BeautifulSoup 6 | 7 | def speak(value): 8 | engine = pyttsx.init() 9 | voices = engine.getProperty('voices') 10 | engine.setProperty('voice', voices[4].id) 11 | rate = engine.getProperty('rate') 12 | engine.setProperty('rate', rate-30) 13 | engine.say(value) 14 | engine.runAndWait() 15 | 16 | url='http://www.cricbuzz.com/' 17 | headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'} 18 | 19 | 20 | def match(): 21 | source_code = requests.get(url, headers=headers, timeout=5) 22 | plain_text=source_code.text 23 | soup=BeautifulSoup(plain_text,"html.parser") 24 | 25 | 26 | 27 | link=soup.find('div',{'class':'cb-ovr-flo cb-hmscg-tm-nm'}) 28 | team=link.string 29 | 30 | link2=soup.findAll('div',{'class':'cb-ovr-flo'}) 31 | score=link2[2].string 32 | 33 | link3=soup.findAll('div',{'class':' cb-ovr-flo cb-text-live'}) 34 | required=link3[0].string 35 | 36 | print team+' '+score 37 | print required 38 | speak(team+'scored'+score) 39 | speak(required) 40 | 41 | while(1): 42 | match() 43 | time.sleep(30) 44 | -------------------------------------------------------------------------------- /kiara.py: -------------------------------------------------------------------------------- 1 | import wx 2 | import pyttsx 3 | import wikipedia 4 | import wolframalpha 5 | import os 6 | # os.environ["HTTPS_PROXY"] = "http://user:pass@192.168.1.107:3128" 7 | 8 | 9 | def speak(value): 10 | engine = pyttsx.init() 11 | voices = engine.getProperty('voices') 12 | engine.setProperty('voice', voices[4].id) 13 | rate = engine.getProperty('rate') 14 | engine.setProperty('rate', rate-30) 15 | engine.say(value) 16 | engine.runAndWait() 17 | 18 | 19 | class MyFrame(wx.Frame): 20 | def __init__(self): 21 | wx.Frame.__init__(self, None, pos=wx.DefaultPosition, 22 | size=wx.Size(450, 100), 23 | style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | 24 | wx.CLOSE_BOX | wx.CLIP_CHILDREN, title='KIARA') 25 | panel = wx.Panel(self) 26 | my_sizer = wx.BoxSizer(wx.VERTICAL) 27 | lbl = wx.StaticText(panel, label='''Hello I\'m Kiara the Python 28 | Digital Assistant. How can I help you?''') 29 | my_sizer.Add(lbl, 0, wx.ALL, 5) 30 | self.txt = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER, 31 | size=(400, 30)) 32 | self.txt.SetFocus() 33 | self.txt.Bind(wx.EVT_TEXT_ENTER, self.OnEnter) 34 | my_sizer.Add(self.txt, 0, wx.ALL, 5) 35 | panel.SetSizer(my_sizer) 36 | self.Show() 37 | speak('Welcome my friend. I am Kiara. How can I help ?') 38 | 39 | def OnEnter(self, event): 40 | input = self.txt.GetValue() 41 | # input = input.lower() 42 | app_id = '2V3684-LXELTTTJ9J' 43 | try: 44 | # wolframalpha 45 | client = wolframalpha.Client(app_id) 46 | res = client.query(input) 47 | ans = next(res.results).text 48 | print(ans) 49 | speak(ans) 50 | except: 51 | # wikipedia 52 | input = input.split(' ') 53 | input = ' '.join(input[2:]) 54 | print(wikipedia.summary(input)) 55 | speak('Searched wikipedia for '+input) 56 | 57 | 58 | if __name__ == "__main__": 59 | app = wx.App(True) 60 | frame = MyFrame() 61 | app.MainLoop() 62 | -------------------------------------------------------------------------------- /loremipsum.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | # Lorem Ipsum API, get one short paragraph 4 | url = "http://loripsum.net/api/1/short/plaintext" 5 | text = requests.get(url).text 6 | # Remove unused lines 7 | text = text.split('\n')[0] 8 | 9 | print(text) -------------------------------------------------------------------------------- /mail_parser.py: -------------------------------------------------------------------------------- 1 | #Reading inbox emails from CLI. 2 | #!/usr/bin/env python 3 | # -*- coding: utf-8 -*- 4 | # __author__ == 'abhinav anand' 5 | 6 | import base64, imaplib, email, re, os 7 | import getpass 8 | from bs4 import BeautifulSoup 9 | imaplib._MAXLINE = 400000 10 | 11 | ORG_EMAIL = "@gmail.com" 12 | FROM_EMAIL = "inboxmeabhinav" + ORG_EMAIL 13 | FROM_PWD = getpass.getpass() 14 | SMTP_SERVER = "imap.gmail.com" 15 | SMTP_PORT = 993 16 | 17 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) 18 | mail.login(FROM_EMAIL, FROM_PWD) 19 | mail.list() 20 | mail.select('inbox') 21 | 22 | i = 0 23 | 24 | def main(): 25 | global i 26 | clear() 27 | mail = imaplib.IMAP4_SSL(SMTP_SERVER) 28 | mail.login(FROM_EMAIL, FROM_PWD) 29 | mail.list() 30 | mail.select('inbox') 31 | inp = 'n' 32 | 33 | 34 | while(inp!='q'): 35 | print('Fetching mails. Please wait...') 36 | if inp == 'n': 37 | i += 1 38 | elif inp == 'p' and i != 1: 39 | i -= 1 40 | else: 41 | print('Please enter valid input.') 42 | result, data = mail.uid('search', None, "ALL") # search and return uids instead 43 | latest_email_uid = data[0].split()[-i] # fetch mails 44 | result, data = mail.uid('fetch', latest_email_uid, '(RFC822)') 45 | raw_email = data[0][1] 46 | email_message = email.message_from_string(raw_email) 47 | 48 | clear() # clear screen and print mail 49 | print 'To:', email_message['To'] 50 | print 'Sent from:', email_message['From'] 51 | print 'Date:', email_message['Date'] 52 | print 'Subject:', email_message['Subject'] 53 | print '*'*30, 'MESSAGE', '*'*30 54 | maintype = email_message.get_content_maintype() 55 | #print maintype 56 | 57 | if maintype == 'multipart': # get the body of the mail 58 | print email_message.get_payload()[0].get_payload() # to get the plain text only 59 | elif maintype == 'text': 60 | line = email_message.get_payload()[ 0 ] 61 | print line 62 | print '*'*69 63 | welcome() 64 | inp = raw_input('>> Enter your choice: ').lower() 65 | 66 | 67 | 68 | def clear(): 69 | os.system('cls' if os.name == 'nt' else 'clear') 70 | 71 | def welcome(): 72 | print '\n' 73 | print '>> Enter \'n\' to check NEXT mail' 74 | print '>> Enter \'p\' to check PREVIOUS mail' 75 | print '>> Enter \'q\' to QUIT' 76 | 77 | if __name__ == '__main__': 78 | main() 79 | -------------------------------------------------------------------------------- /pokeapi.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | # Documentation of pokedata: 4 | # http://pokeapi.co/docsv2/#pokemon-section 5 | 6 | def poke_request(pokemon): 7 | url = "http://pokeapi.co/api/v2/pokemon/" 8 | response = requests.get(url + pokemon) 9 | poke_data = {} 10 | 11 | if response.ok: 12 | data = response.json() 13 | poke_data['Name'] = data['name'][0].upper() + data['name'][1:] 14 | poke_data['ID'] = data['id'] 15 | poke_data['Height'] = str(data['height']/10) + " m" 16 | poke_data['Weight'] = str(data['weight']/10) + " kg" 17 | img_url = data['forms'][0]['url'] 18 | poke_data['img'] = image_request(img_url) 19 | 20 | # if poke_data: 21 | # for key in poke_data.keys(): 22 | # print("{}: {}".format(key, poke_data[key])) 23 | return poke_data 24 | 25 | else: 26 | print("Bad conection, try again later.") 27 | return None 28 | 29 | def image_request(url): 30 | response = requests.get(url) 31 | if response.ok: 32 | data = response.json() 33 | return data['sprites']['front_default'] 34 | 35 | if __name__ == '__main__': 36 | # This is a test: 37 | pokemon = "pikachu" 38 | pd = poke_request(pokemon) 39 | print(pd) 40 | -------------------------------------------------------------------------------- /quora.py: -------------------------------------------------------------------------------- 1 | import os 2 | import webbrowser 3 | import sys 4 | from colorama import Fore, Back, Style 5 | from colorama import init 6 | init() 7 | #os.environ["HTTPS_PROXY"] = "http://username:pass@192.168.1.107:3128" 8 | import requests 9 | from bs4 import BeautifulSoup 10 | import time 11 | 12 | headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'} 13 | 14 | 15 | #Take query and convert into search parameter 16 | #query=input('Ask your Quora que: ') 17 | arg = sys.argv 18 | query = '' 19 | for i in range(1,len(arg)-2): 20 | query=query+arg[i] 21 | query=query+'+' 22 | print(query) 23 | #retrieve query 24 | 25 | url='https://www.quora.com/search?q='+query 26 | source_code = requests.get(url, headers=headers, timeout=15) 27 | plain_text=source_code.text 28 | soup=BeautifulSoup(plain_text,"html.parser") 29 | 30 | #get the relevant questions list 31 | que_list=soup.findAll('a',{'class':'question_link'}) 32 | 33 | hrefs=list(que_list) 34 | #convert into user-friendly string 35 | print(Fore.GREEN+' << Showing some relevant questions asked >>') 36 | for i in range(len(que_list)): 37 | que_list[i]['href']=que_list[i]['href'].replace('-',' ') 38 | que_list[i]['href']=que_list[i]['href'].replace('/','') 39 | print(str(i+1)+'. '+que_list[i]['href']) 40 | print(' <-------------------------------/-------------------------------->') 41 | #get_inp=input('Select a question from the above > ') 42 | get_inp = arg[len(arg)-2] 43 | #retrieve the page with that answer 44 | url='https://www.quora.com/'+hrefs[int(get_inp)-1]['href'].replace(' ','-') 45 | try: 46 | source_code = requests.get(url, timeout=15) 47 | plain_text=source_code.text 48 | soup=BeautifulSoup(plain_text,"html.parser") 49 | ans=soup.findAll('div',{'class':'AnswerHeader ContentHeader'}) 50 | header=ans[0].text 51 | nans=ans[0].parent 52 | mans=nans.next_sibling 53 | #man=mans.findNextSibling() 54 | text=mans.text 55 | pos=text.find('Upvotes') 56 | uf=text[0:pos+7] 57 | print(Fore.BLUE+header) 58 | print(uf) 59 | except Exception as e: 60 | print(e) 61 | print('Sorry, this que hasn\'t been answered.') 62 | print(' <----------------------------------/------------------------------->') 63 | #a=input('Head over to the link for more answers?(y/n) ') 64 | a= arg[len(arg)-1] 65 | if a is 'y': 66 | webbrowser.open(url) 67 | time.sleep(2) 68 | exit() 69 | -------------------------------------------------------------------------------- /requirement.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4==4.4.1 2 | requests==2.9.1 3 | colorama==0.3.9 4 | -------------------------------------------------------------------------------- /trending_tweet_db/get_trending.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | try: 4 | import json 5 | except ImportError: 6 | import simplejson as json 7 | 8 | # Import the necessary methods from "twitter" library 9 | from twitter import Twitter, OAuth, TwitterHTTPError, TwitterStream 10 | from keys import ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET 11 | import sqlite3 12 | 13 | conn = sqlite3.connect('tweet_db.db') 14 | 15 | conn.execute('''DROP TABLE IF EXISTS TWEETS;''') 16 | 17 | conn.execute('''CREATE TABLE IF NOT EXISTS TWEETS 18 | (ID INT PRIMARY KEY NOT NULL, 19 | screen_name TEXT NOT NULL, 20 | tweet_time TEXT NOT NULL, 21 | favorite_count INT, 22 | query TEXT, 23 | retweet_count INT) 24 | ;''') 25 | 26 | # print ACCESS_TOKEN, ACCESS_SECRET 27 | oauth = OAuth(ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET) 28 | 29 | # Initiate the connection to Twitter Streaming API 30 | twitter = Twitter(auth=oauth) 31 | 32 | # get the trending topics in India 33 | sfo_trends = twitter.trends.place(_id = 23424848) 34 | 35 | 36 | # print json.dumps(sfo_trends, indent=4) 37 | # print len(sfo_trends[0]['trends']) 38 | length = len(sfo_trends[0]['trends']) 39 | topics = [sfo_trends[0]['trends'][i]['name'] for i in range(length)] 40 | print topics 41 | pk = 1 42 | for topic in topics: 43 | tweet = twitter.search.tweets(q=topic, result_type='recent', lang='en', count=1) 44 | try: 45 | screen_name = tweet['statuses'][0]['user']['screen_name'] 46 | except: 47 | continue 48 | tweet_time = tweet['statuses'][0]['created_at'] 49 | try: 50 | favorite_count = tweet['statuses'][0]['retweeted_status']['favorite_count'] 51 | except KeyError: 52 | favorite_count = 0 53 | retweet_count = tweet['statuses'][0]['retweet_count'] 54 | query = tweet['search_metadata']['query'] 55 | # print query, screen_name, tweet_time, favorite_count, retweet_count 56 | row = (pk, screen_name, tweet_time, favorite_count, query, retweet_count) 57 | conn.execute('''INSERT INTO TWEETS (ID, screen_name, tweet_time, favorite_count, query, retweet_count) 58 | VALUES (?, ?, ?, ?, ?, ?)''', row) 59 | conn.commit() 60 | pk += 1 61 | print 'done' 62 | 63 | conn.close() -------------------------------------------------------------------------------- /trending_tweet_db/tweet_db.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ab-anand/Automation-Bots/3467e717179e18cc934b43129c22db0d8c34e227/trending_tweet_db/tweet_db.db -------------------------------------------------------------------------------- /vurl.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import argparse 3 | 4 | def shortener(link): 5 | r = requests.get('http://vurl.com/api.php?url={}'.format(link)) 6 | return r.text 7 | 8 | if __name__ == '__main__': 9 | parser = argparse.ArgumentParser() 10 | parser.add_argument("-l", "--links", 11 | help="Links to shorten.", 12 | nargs='+', 13 | type=str, required=True) 14 | args = parser.parse_args() 15 | for i in args.links: 16 | try: 17 | shortened_link = shortener(i) 18 | except: 19 | shortened_link = 'ERROR' 20 | if len(i) > 30: 21 | print('{:<34} - {}'.format(i[:30]+'...', shortened_link)) 22 | else: 23 | print('{:<34} - {}'.format(i[:30], shortened_link)) 24 | -------------------------------------------------------------------------------- /whatsapp-web-send-message.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | chrome_driver = 'C:/Users/Aashish/Downloads/chromedriver_win32/chromedriver' 4 | driver = webdriver.Chrome(chrome_driver) 5 | driver.get('http://web.whatsapp.com') 6 | 7 | name = input('Enter the name of user or group : ') 8 | msg = input('Enter the message : ') 9 | 10 | input('Enter anything after scanning QR code') 11 | 12 | user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name)) 13 | user.click() 14 | 15 | msg_box = driver.find_element_by_class_name('_2S1VP') 16 | msg_box.send_keys(msg) 17 | driver.find_element_by_class_name('_35EW6').click() 18 | -------------------------------------------------------------------------------- /wiki-crawler.py: -------------------------------------------------------------------------------- 1 | # A fun little crawler to see how many steps are between two articles. 2 | # Uses only standard libraries. 3 | # Note: Will most likely not take the same path twice. 4 | 5 | import re 6 | import urllib.request 7 | from time import sleep 8 | from random import randint 9 | 10 | def Main(x, y): 11 | z = urllib.request.urlopen('https://wikipedia.org/wiki/' + x).read() 12 | z = z.decode('utf-8') 13 | f = re.findall( 14 | r'