def post(self, user_name, project_name): # config = configparser.ConfigParser() # config.read('../grafluent.ini') bucket_name = os.getenv('DEFAULT_BUCKET') parser = reqparse.RequestParser() parser.add_argument('query', required=True, help='Please provide a valid search query.', trim=True), parser.add_argument('num_req', required=True, type=int, help='Please provide the number of requests for News API') args = parser.parse_args() article = news(query=args['query']) articles = article.createDF(args['num_req']) df_list = articles.values.tolist() if(df_list): fname = article.getName().replace(" ", "_").lower() csv = bucket_name.strip() + '/%s/%s/source_documents/news_%s.csv' % (user_name.strip(), project_name.strip(), fname.strip()) with s3.open(csv, 'w') as file: articles.to_csv(file) return { 'status' : 'Posted new data', 'file_name' : str(fname) + '.csv', 'articles' : df_list }, 201 else : return { 'status' : 'Please enter valid query' }, 400
def index(): '''This module is what connects the modules and then shows this on the webpapge''' #getting the information from the form on the webpage\ #when the user submits their alarm the alarm alarm = str(request.args.get("alarm")) #the label for the alarm name = request.args.get("two") #whether they want a news update in the alarm or not inclnews = request.args.get("news") #whether they want a weather update in the alarm or not inclweather = request.args.get("weather") #if the user decides to delete an alarm delete = request.args.get("alarm_item") #if the user decides to delete a notification rem_notif = request.args.get("notif") #passing the delete info to the remove function if delete: remove_alarm(delete, True) if rem_notif: remove_notification(rem_notif) #using the covid function to get the latest stats from the api covid = get_covid() #using the news function to get the latest news from the news api articles = news() #using the weather function to get the latest weather from the weather api weather = weathers() #setting a blank variable to be used in the alarm function calls temp = '' #using if statements to decide what to call the alarm with dependin on user inputs if inclnews == 'news' and inclweather == 'weather': pick_news = True pick_weather = True #calling the add alarm function to add the details the user inputted to the json file alarmj = add_alarm(alarm, name, weather, articles, covid, pick_news, pick_weather) elif inclweather: pick_news = False pick_weather = True alarmj = add_alarm(alarm, name, weather, temp, covid, pick_news, pick_weather) elif inclnews: pick_news = True pick_weather = False alarmj = add_alarm(alarm, name, temp, articles, covid, pick_news, pick_weather) else: pick_news = False pick_weather = False alarmj = add_alarm(alarm, name, temp, temp, covid, pick_news, pick_weather) if name is None: #checking and refreshing the alarms to the latest weather, news and covid info alarmj = refresh(covid, articles, weather) #putting all the updates (covid,news,weather) into one dictionary\ #to be passed to the html as notifications organised = org_func(covid, weather, articles) #rendering all this informaion to the html template as a website return render_template('template.html', notifications=organised, alarms=alarmj,\ image='icons8-clock-64.png')
def get_news(event, context): return { "statusCode": 200, "headers": { "Access-Control-Allow-Origin": "*" }, "body": json.dumps(news()) }
def get_news_from_source(event, context): return { "statusCode": 200, "headers": { "Access-Control-Allow-Origin": "*" }, "body": json.dumps(news(event['pathParameters']['source_id'])) }
def preferences(): form = PreferencesForm() if form.validate_on_submit(): flash('Your changes have been made!', 'success') newsobj = news() newsobj.update(form.query.data, form.time.data, form.sortBy.data) session['articles'] = newsobj.articles return redirect(url_for('home')) return render_template('preferences.html', form=form)
def clean_data(self, data: dict) -> list: cleaned_data: list = [] for datum in data: # extract wanted fields only from the article. current_article = news(datum['title'], datum['url'], 'newsapi') cleaned_data.append(current_article) if len(cleaned_data) == self.articles_limit: break return cleaned_data
def processRequest(req): # Parsing the POST request body into a dictionary for easy access. req_dict = json.loads(request.data) entity_type = "" entity_value = "" speech = "" # Accessing the fields on the POST request boduy of API.ai invocation of the webhook intent = req_dict["result"]["metadata"]["intentName"] entity_key_val = req_dict["result"]["parameters"] for key in entity_key_val: entity_value = entity_key_val[key] entity_type = key # constructing the resposne string based on intent and the entity. if intent == "shopping - custom": my_input = (req.get("result").get("resolvedQuery")).lower() search_results = webscrap(my_input) res = makeWebhookResult(search_results) elif intent=="showwallet": bal=10 res= makeWebhookResult(bal) elif intent == "Default Fallback Intent": my_input = (req.get("result").get("resolvedQuery")).lower() if ("weather" in my_input) or ('tell me about weather condition' in my_input) or ( 'tell me about weather' in my_input) or ('whats the climate' in my_input): x = weather() speech = "" + x + "" res = makeWebhookResult(speech) elif ("news" in my_input) or ("top headlines" in my_input) or ("headlines" in my_input): x = news() speech = "" + x + "" res = makeWebhookResult(speech) else: try: app_id = "R2LUUJ-QTHXHRHLHK" client = wolframalpha.Client(app_id) r = client.query(my_input) answer = next(r.results).text speech = "" + answer + "" res = makeWebhookResult(speech) except: my_input = my_input.split(' ') my_input = " ".join(my_input[2:]) answer = wikipedia.summary(my_input, sentences=2) speech = "" + answer + "" res = makeWebhookResult(speech) else: speech = "no input" res = makeWebhookResult(speech) return res
def clean_data(self, data: list) -> list: cleaned_data: list = [] for datum in data: # only extract wanted fields from the article details. current_article = news(datum['data']['title'], datum['data']['url'], 'reddit') cleaned_data.append(current_article) if len(cleaned_data) == self.articles_limit: break return cleaned_data
def index(): return render_template("index.html", today=dtime(), data=weather()[0]['臺北市'], data1=weather()[1]['臺北市'], data2=weather()[2]['臺北市'], usd=tb()[0], jpy=tb()[7], aud=tb()[3], eur=tb()[14], news=news())
def reply_message(msg): if (msg == 'news updates'): return news.news() if (msg.split()[0] == 'weather'): return weather.get_weather(msg.split()[1]) if (msg.split()[0] == 'definition'): return dictionary.get_definition(msg.split()[1]) if (msg.split()[0:2] == ['covid', 'update']): return tracker.get_corona_updates(msg.split()[2]) else: return "I dont understand"
def getRequests(arr): nested_arr = [] for i in arr: print(i) url = "http://newsapi.org/v2/top-headlines?q=%s&from=2020-09-24&sortBy=publishedAt&apiKey=537a36338c1e4d119f54dfec8f08ba9b" % i print(url) page = get(url) page.encoding = page.apparent_encoding json_page = dict(loads(page.text))["articles"] news_list = list() for i in json_page: newNewsObject = news() newNewsObject.assign_attributes(i) news_list.append(newNewsObject) nested_arr.append(news_list) return nested_arr
def reply_message(msg): if(msg=='news updates'): return news.news() if(msg.split()[0]=='weather'): return weather.get_weather(msg.split()[1]) if(msg.split()[0]=='Weather'): return weather.get_weather(msg.split()[1]) if(msg.split()[0]=='definition'): return dictionary.get_definition(msg.split()[1]) if(msg.split()[0:2]==['covid','update']): return tracker.get_corona_updates(msg.split()[2]) else: return '''Hello, I am a WhatsApp Chatbot made by Vineet Kekatpure,Shreyash Joshi, Sandeep Suhag and Rithik Kalla.\n
def remove_alarm(title, status=False): '''This function opens the json file for the alarms and then it loops through the file until the title is the same and it removes that alarm''' with open('./json_files/alarms.json') as jfile: data = json.load(jfile) #getting the alarms from the json file temp = data['alarms'] #the number of alarms in the file length = len(temp) #looping through each alarm in the list for i in range(length): #then checkign each alarm title agaist the input title, #and if they are the same this will remove it if temp[i]["title"] == title: temp.pop(i) log("alarm for " + title + " has been removed") break #re-wrtiting the updated alarms to the json file with open('./json_files/alarms.json', 'w') as jfile: json.dump(data, jfile, indent=4) length = len(lst) if status: #looping through the scheduler list for i in range(length): try: #canceling the events in the list s.cancel(lst[i]) #logging that this has been done log('alarm ' + title + ' removed from scheduler') except: log('alarm' + title + 'could not be removed from the scheduler') #removing the item from the list lst.clear() if not status: refresh(get_covid(), news(), weathers())
def processRequest(req): # Parsing the POST request body into a dictionary for easy access. speech = "" try: action = req.get('queryResult').get('action') except AttributeError: return 'json error' if action == "medicalissues.medicalissues-custom": my_input = ( req.get("queryResult").get("parameters").get("medical")).lower() x = database(my_input) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "Diabetes.Diabetes-custom.Diabetes-Type1-no.Diabetes-Type1-no-custom": my_input = my_input = req.get('queryResult').get('queryText').lower() x = nearby_pharmacy(my_input) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "Diabetes.Diabetes-custom.Diabetes-Type1-yes.Diabetes-Type1-yes-custom.Diabetes-Type1-yes-a-no.Diabetes-Type1-yes-a-no-yes.Diabetes-Type1-yes-a-no-yes-custom": my_input = my_input = req.get('queryResult').get('queryText').lower() x = nearby_pharmacy(my_input) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "Diabetes.Diabetes-custom.Diabetes-Type1-yes.Diabetes-Type1-yes-custom.Diabetes-Type1-yes-a-yes": #print (sa_time.strftime('%Y-%m-%d_%H-%M-%S')) hour = int(sa_time.strftime('%H')) if (7 <= hour < 11): greeting = "It's around 9 Am Did you have your Breakfast !" elif (11 <= hour < 18): greeting = "It's around 6 pm" + " Did you have your lunch !" else: greeting = "It's around 9 Am Did you have your Dinner !" speech = "" + greeting + "" res = makeWebhookResult(speech) elif action == "menstrualcycle": x = menstrualcycle() speech = "" + x + "" res = makeWebhookResult(speech) elif action == "pregnancy.pregnancy-custom": data = (req.get("queryResult").get("parameters").get("number")) x = pregnancy(data) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "pharmacy.pharmacy-custom": my_input = req.get('queryResult').get('queryText').lower() x = nearby_pharmacy(my_input) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "finddoctor.finddoctor-custom": my_input = req.get('queryResult').get('queryText').lower() x = doctor_find(my_input) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "findhospital.findhospital-custom": my_input = req.get('queryResult').get('queryText').lower() x = hospitalfind(my_input) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "fitness.fitness-custom": height = req.get('queryResult').get('parameters').get('height') weight = req.get('queryResult').get('parameters').get("weight") age = req.get('queryResult').get('parameters').get('age').get('amount') age = int(age) age = str(age) gender = req.get('queryResult').get('parameters').get('gender') x = bmi(height, weight, gender, age) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "weather.weather-custom": my_input = req.get('queryResult').get('queryText').lower() x = weather(my_input) speech = "" + x + "" res = makeWebhookResult(speech) elif action == "input.unknown": my_input = req.get('queryResult').get('queryText').lower() if ("news" in my_input) or ("top headlines" in my_input) or ("headlines" in my_input): x = news() speech = "" + x + "" res = makeWebhookResult(speech) else: try: app_id = "R2LUUJ-QTHXHRHLHK" client = wolframalpha.Client(app_id) r = client.query(my_input) answer = next(r.results).text speech = "" + answer + "" res = makeWebhookResult(speech) except: my_input = my_input.split(' ') my_input = " ".join(my_input[2:]) answer = wikipedia.summary(my_input, sentences=2) speech = "" + answer + "" res = makeWebhookResult(speech) else: speech = "no input" res = makeWebhookResult(speech) return res
# coding=utf-8 from appium import webdriver from time import sleep from homepage import home from market import market from trade import trade from news import news desired_caps = { 'platformName': 'iOS', 'noReset': True, 'platformVersion': '10.3', "deviceName": "iPhone 6s Plus", "bundleId": "com.lanyilive.YXFuture", "udid": "6eaec690714d9d23c386339e0c07268109d9fabc", "automationName": "XCUITest" } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) sleep(2) x = driver.get_window_size()['width'] y = driver.get_window_size()['height'] home(driver, x, y) market(driver) trade(driver) news(driver, x, y)
def AssistantSkill(cmd): try: if vision.split(cmd) in web_dict: search.search_web(cmd) return elif cmd in media_toggle[0]: vision.speak("opening your music player") mediaplayer.music() return elif cmd in media_toggle[1]: vision.speak("opening your video player") mediaplayer.video() return elif 'send email' in cmd or 'sent mail' in cmd: mail.mail() return elif "who are you" in cmd or "define yourself" in cmd: speaks = '''Hello, I am Person. Your personal Assistant. I am here to make your life easier. You can command me to perform various tasks such as calculating sums or opening applications etc ''' vision.speak(speaks) return elif "who made you" in cmd or "created you" in cmd: speaks = "I have been created by Developer." vision.speak(speaks) return elif "calculate" in cmd.lower(): wolframalph.WolframSkills(cmd) return elif cmd in frequent[1]: date_time.tell_the_date() return elif cmd in frequent[0]: date_time.tell_the_time() return elif cmd in system_toggle: systeminfo.SystemInfo() return elif 'network speed' in cmd: netinfo.Speed() return elif 'check internet connection' in cmd: netinfo.InternetConnection() return elif 'open' in cmd: desktopapps.open_application(cmd) return elif 'close' in cmd: desktopapps.close_application(cmd) return elif 'news' in cmd: news.news(cmd) return elif "weather" in cmd: weather.main(cmd) return elif cmd in whereAbouts: location.location() return elif "shutdown" in cmd: os.system("shutdown /s /t 1") return elif "restart" in cmd: os.system("shutdown /r /t 1") return else: vision.speak("Please check my skill listed in info file...") return except Exception as e: vision.speak(e) return
def main(): st.title('COVID - 19') menuItems=['Guidelines','India Statistics','Worldwide Statistics','Hospital Stats India','Symptoms','Helpline'] st.sidebar.title('Menu') itemSelected=st.sidebar.selectbox('',menuItems) hide_streamlit_style = """ <style> #MainMenu {visibility: hidden;} footer {visibility: hidden;} </style> """ st.markdown(hide_streamlit_style, unsafe_allow_html=True) github='''[ Fork/Star on Github](https://github.com/abhayrpatel10/COVID-19)''' st.sidebar.info(github) if(itemSelected=='Helpline'): st.markdown(helpline()) if(itemSelected=='Hospital Stats India'): hospitals() if(itemSelected=='India Statistics'): indianStats() if(itemSelected=='Guidelines'): langugaes=['English','हिंदी','ગુજરાતી','தமிழ்','తెలుగు','ਪੰਜਾਬੀ','മലയാളം','ಕನ್ನಡ'] lang=st.selectbox('Choose Language',langugaes) st.subheader('WHO Guidelines') if(lang=='English'): st.markdown(english()) elif(lang=='தமிழ்'): st.markdown(tamil()) elif(lang=='हिंदी'): st.markdown(hindi()) elif(lang=='ગુજરાતી'): st.markdown(gujarati()) elif(lang=='తెలుగు'): st.markdown(telugu()) elif(lang=='ਪੰਜਾਬੀ'): st.markdown(punjabi()) elif(lang=='മലയാളം'): st.markdown(malayalam()) elif(lang=='ಕನ್ನಡ'): st.markdown(kannada()) if(itemSelected=='Worldwide Statistics'): ogstatsurl='https://coronavirus-tracker-api.herokuapp.com/v2/latest' #making get request to the API client=request(ogstatsurl) data=client.read() client.close() #bytes to json final=json.loads(data) #number of confirmed cases all around the world ---------variable name - confnum confnum=final['latest']['confirmed'] confirmed='''## Confirmed Cases ``` %d``` '''%(confnum) st.markdown(confirmed) #number of deaths around the world ---------variable name -deathnum deathnum=final['latest']['deaths'] deaths='''## Deaths ``` %d ``` '''%(deathnum) st.markdown(deaths) ##Getting recovered data # url='https://www.worldometers.info/coronavirus/' # client=request(url) # raw_html=client.read() # parsed_html=soup(raw_html,'html.parser') # #-----------Number of people recovered -variable name - =recoverednum # #using beautiful soup to find div tag with given style # recoverednum=parsed_html.find('div',{'style':'color:#8ACA2B '}).text # recoverednum=recoverednum.strip().replace(",","") # recovered='''## Recovered ``` %s ``` '''%(recoverednum) # st.markdown(recovered) objects = ('Deaths', 'Total Cases')#labels for the bar chart y_pos = np.arange(len(objects)) #active=int(confnum)-(int(recoverednum)+int(deathnum))#finding number of active cases values = [int(deathnum),int(confnum)]#values for the bar chart ax=plt.bar(y_pos, values, align='center', alpha=0.7)#bar chart ----plotted using matplotlib plt.xticks(y_pos, objects) # Additional data for the graph plt.title('COVID-19') autolabel(ax) st.write(mpl_fig=ax) st.pyplot() df=getdata() #getting the list of countries country_list=df['Country'].tolist() country_list=sorted(list(set(country_list))) choice=st.selectbox('Choose Country',country_list) #finding data related to specific country and displaying value=df.loc[df['Country']==choice] st.table(value) #dsplaying all data st.table(df) if(itemSelected=='News'): st.subheader('News') image = Image.open('verified.png') st.image(image) choice=st.selectbox('Choose state or UT',list_cities()) st.markdown(news(choice)) st.markdown('# Central News') st.markdown(news()) if(itemSelected=='Symptoms'): st.markdown(symptoms()) st.write('Source : WHO')
def news_from_source(source_id): return news(source_id)
def all_news(): return news()
if choose_options == "Home Page": infopage() ticker = homepage() choose_options = st.sidebar.radio( "Options", ["Company Analysis", "Close/Return", "News"], ) if choose_options == "Company Analysis": summary_page_load(ticker) elif choose_options == "Close/Return": plotData(ticker) else: ticker_obj = get_ticker_object(ticker) ticker_info = ticker_obj.info # query = ticker_info['longName'].replace("Inc.","") n = news(f"{ticker_info['industry']}") all_news = n.cleanup_news() if all_news and len(all_news) > 0: for news in all_news: col1, col2 = st.beta_columns(2) try: response = requests.get(news["urlToImage"]) image = Image.open(BytesIO(response.content)) except: image = Image.open("static_data/no_image.png") col1.image(image, caption=f"Source : {news['source']}", use_column_width=True) col2.markdown(f"[{news['title']}]({news['url']})") else: st.title("Sorry! couldn't find any news for you.")
from music import music from news import news from tts import tts from vts import vts from its import its from mail import mail from wea import weather from bot import bot from wiki import wiki # Infinite Loop count = 0 while 1: tts(mail()) tts(weather('jabalpur')) tts(news()) while 1: string = str(input("Ask -> ")) if "weather report" in string: location = str(input("Enter LOC -> ")) tts(weather(location)) elif "news" in string: tts(news()) elif "mail" in string: tts(mail()) elif "song" in string: tts("Which song you wanna listen") song = str(input("Song -> ")) music(song) elif "neola" in string: string = string.replace("neola search ", "")
def test_old_news(): lst = [1] assert len(news()) > 0
def fill(): engine = create_engine("sqlite:///news.db") Base.metadata.create_all(engine) if not database_exists(engine.url): create_database(engine.url) Session = sessionmaker(bind=engine) session = Session() # add categorised news to the db # all news news(thisSession=session, url=all_url, model=AllNews) # general news news(thisSession=session, url=gb_general_url, model=GeneralNews) news(thisSession=session, url=us_general_url, model=GeneralNews, delete=False) # sports news news(thisSession=session, url=gb_sports_url, model=SportsNews) news(thisSession=session, url=us_sports_url, model=SportsNews, delete=False) # tech news news(thisSession=session, url=gb_tech_url, model=TechNews) news(thisSession=session, url=us_tech_url, model=TechNews, delete=False) # science news news(thisSession=session, url=gb_science_url, model=ScienceNews) news(thisSession=session, url=us_science_url, model=ScienceNews, delete=False) # health news news(thisSession=session, url=gb_health_url, model=HealthNews) news(thisSession=session, url=us_health_url, model=HealthNews, delete=False) # business news news(thisSession=session, url=gb_business_url, model=BusinessNews) news(thisSession=session, url=us_business_url, model=BusinessNews, delete=False) # entertainment news news(thisSession=session, url=gb_entertainment_url, model=EntertainmentNews) news(thisSession=session, url=us_entertainment_url, model=EntertainmentNews, delete=False)
def homepage(): description, title, desc_url, image_url = news() return render_template("news.html", news=zip(description, title, desc_url, image_url))
audio = r.listen(source) Mytext = r.recognize_google(audio) Mytext = Mytext.lower() print(Mytext) if ("time" in Mytext): date_time = dt() text_to_speech(" the time is " + str(date_time)) if ("date" in Mytext): date_time = dt() text_to_speech(" the time is " + str(date_time)) if ("weather" in Mytext): temperature, humidity, pressure, cond = weather(city) text_to_speech("the temperature is " + str(temperature) + "and" + str(cond)) if ("news" in Mytext): keyword = stp_words(Mytext) story = news(keyword) summ = summary(story) text_to_speech(summ) if (Mytext[len(Mytext) - 4:] == 'quit'): start = False except sr.RequestError as e: print("Could not request results; {0}".format(e)) except sr.UnknownValueError: print("unknown error occured")
async def scrape_news(query): return new.news(query)
def news_query(): return news.news()
def test_new_news(): lst = [] assert news() != [{'title': 'FAILED', 'content': "couldn't get news data"}]
def news_message(message): news.news(message)
from news import news import re import nltk import heapq from t2s import text_to_speech nltk.download('stopwords') keywords = 'corona' article_text = news(keywords) print(article_text) article_text = re.sub(r'\[[0-9]*\]', ' ', article_text) article_text = re.sub(r'\s+', ' ', article_text) formatted_article_text = re.sub('[^a-zA-Z]', ' ', article_text) formatted_article_text = re.sub(r'\s+', ' ', formatted_article_text) sentence_list = nltk.sent_tokenize(article_text) stopwords = nltk.corpus.stopwords.words('english') word_frequencies = {} for word in nltk.word_tokenize(formatted_article_text): if word not in stopwords: if word not in word_frequencies.keys(): word_frequencies[word] = 1 else: word_frequencies[word] += 1