Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
frame2 = tk.Frame(master=window,width=50,height=50,bg="green")
frame2.pack(fill=tk.X)
frame3 = tk.Frame(master=window,width=20,height=20,bg="Red")
frame3.pack(fill=tk.Y expand="true")
frame3.pack(fill=tk.Y, expand="true")
window.mainloop()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions Python_Examples/Wikipedia-Parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Wiki Scrapper
Extracts information from wikipedia pages.

Reference API - [PyPi - Wikipedia](https://pypi.org/project/wikipedia/)

### Usage
```
cd Python/Wiki_Scrapper
pip install -r requirements.txt

# Ping wikipedia to get related topics
py wiki.py --ping "query"

# Get summary for a particular topic
py wiki.py --gist "query"

# Get wikipedia page information for a particular topic
py wiki.py --page "query"

# Set language preference for a search instance
py wiki.py --lang "en"


P.S - All arguments can be used simultaneously

Note: This script is for educational purposes only. Web Scrapping isn't actually allowed by some websites as per their privacy policy
```
1 change: 1 addition & 0 deletions Python_Examples/Wikipedia-Parser/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wikipedia
42 changes: 42 additions & 0 deletions Python_Examples/Wikipedia-Parser/wiki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import wikipedia, argparse

def search_wiki(ping_query, gist_query, page_query, lang='en'):
response = {}
try:
wikipedia.set_lang(lang)
except Exception as e:
print({"message": "TypeError: Unsupported language preference passed. Setting default language preference as 'en'", "error": str(e)})

try:
if ping_query:
topics = wikipedia.search(ping_query)
response["topics"] = {"query": ping_query, "data": topics}

if gist_query:
gist = wikipedia.summary(gist_query)
response["summary"] = {"query": gist_query, "data": gist}

if page_query:
page = wikipedia.page(page_query)
response["page"] = {"query": page_query, "data": {"title": page.title, "url": page.url, "summary": page.summary, "section": page.content}}

print(response)
except Exception as e:
print({"message": "ValueError: Could not extract information from wikipedia", "error": str(e)})


if __name__ == "__main__":
my_parser = argparse.ArgumentParser()
my_parser.add_argument("--ping", action="store", type=str, required=False, help="Gets similar topics for any given query")
my_parser.add_argument("--gist", action="store", type=str, required=False, help="Gets summary for a particular topic")
my_parser.add_argument("--page", action="store", type=str, required=False, help="Gets wiki page for a particular topic")
my_parser.add_argument("--lang", action="store", type=str, required=False, help="Set language preference for a search instance")

args = my_parser.parse_args()

ping, gist, page, lang = args.ping, args.gist, args.page, args.lang

if lang:
search_wiki(ping, gist, page, lang)
else:
search_wiki(ping, gist, page)