├── .gitattributes ├── README.md └── MainModule.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Falsify - Fact Engine 2 | 3 | Have you ever received a shocker message and didn't know if it was true? 4 | Have you ever stood perplexed about a viral news that just came up? 5 | Did you ever want to know, if the facts were true? 6 | 7 | Presenting you, the one stop solution to all of that, Falsify. 8 | 9 | Falsify, is a fact engine that looks up a given fact all over the internet, reads stories, news articles and recognizes if the given fact is a statement of truth or not, later it analyses the statement's genuinity and tells you if it's a Truth/Lie. 10 | -------------------------------------------------------------------------------- /MainModule.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from urllib.parse import urlencode, urlparse, parse_qs 3 | from lxml.html import fromstring 4 | from requests import get 5 | from bs4 import BeautifulSoup 6 | import nltk 7 | import requests 8 | import re 9 | import heapq 10 | 11 | def FactEngine(input_msg): 12 | target_text=str(input_msg) 13 | #Scrapes and Writes into File 14 | fo = open("news.txt", "w",encoding = 'UTF-8') 15 | fo.seek(0, 0) 16 | for n in range(0,10,10): 17 | num=int((n/10)+1) 18 | fo.write("From Page "+str(num)+"\n\n") 19 | target_url="https://www.google.com/search?q="+str(target_text)+"&tbm=nws&start="+str(n) 20 | raw = get(target_url).text 21 | page = fromstring(raw) 22 | for result in page.cssselect(".r a"): 23 | url = result.get("href") 24 | if url.startswith("/url?"): 25 | url = parse_qs(urlparse(url).query)['q'] 26 | fo.write("\n\n"+url[0]) 27 | response = requests.get(url[0]) 28 | soup = BeautifulSoup(response.content, "html.parser") 29 | links = soup.findAll("p") 30 | fo.write("\n\n"+re.sub('<[^>]+>', '',str(links))) 31 | 32 | #NE Tagging Target Text, Important Words Shortlisted 33 | namedEnt = nltk.pos_tag(nltk.word_tokenize(target_text)) 34 | named_entities = [] 35 | search_query = [] 36 | for x in namedEnt: 37 | if x[1] == 'NNP': 38 | named_entities.append(x[0]) 39 | i=0 40 | 41 | while(True): 42 | try: 43 | search_query.append(str(named_entities[i][0][0])) 44 | except Exception as e: 45 | break 46 | i+=1 47 | 48 | #Reading back from File 49 | k=g=0 50 | count=[0]*len(search_query) 51 | while(k60): 64 | print("Trust Me. It's True.") 65 | else: 66 | print("Oh Snap. It's a Lie!") 67 | return 0 --------------------------------------------------------------------------------