Created
April 16, 2018 13:19
-
-
Save srini5/4cb36f99651e094d5ee6026fa3aa8220 to your computer and use it in GitHub Desktop.
Day 1 of #100DaysOfPython
Random Quote Machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project version="4"> | |
| <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6.4 (~/anaconda3/bin/python) (1)" project-jdk-type="Python SDK" /> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project version="4"> | |
| <component name="ProjectModuleManager"> | |
| <modules> | |
| <module fileurl="file://$PROJECT_DIR$/.idea/RandomQuotesMachine.iml" filepath="$PROJECT_DIR$/.idea/RandomQuotesMachine.iml" /> | |
| </modules> | |
| </component> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <module type="PYTHON_MODULE" version="4"> | |
| <component name="NewModuleRootManager"> | |
| <content url="file://$MODULE_DIR$" /> | |
| <orderEntry type="jdk" jdkName="Python 3.6.4 (~/anaconda3/bin/python) (1)" jdkType="Python SDK" /> | |
| <orderEntry type="sourceFolder" forTests="false" /> | |
| </component> | |
| </module> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project version="4"> | |
| <component name="ChangeListManager"> | |
| <list default="true" id="2e503878-b495-421c-abf5-579e2a34cb42" name="Default" comment="" /> | |
| <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> | |
| <option name="TRACKING_ENABLED" value="true" /> | |
| <option name="SHOW_DIALOG" value="false" /> | |
| <option name="HIGHLIGHT_CONFLICTS" value="true" /> | |
| <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> | |
| <option name="LAST_RESOLUTION" value="IGNORE" /> | |
| </component> | |
| <component name="CreatePatchCommitExecutor"> | |
| <option name="PATCH_PATH" value="" /> | |
| </component> | |
| <component name="ExecutionTargetManager" SELECTED_TARGET="default_target" /> | |
| <component name="ProjectFrameBounds"> | |
| <option name="x" value="60" /> | |
| <option name="y" value="61" /> | |
| <option name="width" value="1296" /> | |
| <option name="height" value="707" /> | |
| </component> | |
| <component name="PropertiesComponent"> | |
| <property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" /> | |
| </component> | |
| <component name="ShelveChangesManager" show_recycled="false"> | |
| <option name="remove_strategy" value="false" /> | |
| </component> | |
| <component name="TaskManager"> | |
| <task active="true" id="Default" summary="Default task"> | |
| <changelist id="2e503878-b495-421c-abf5-579e2a34cb42" name="Default" comment="" /> | |
| <created>1523880381711</created> | |
| <option name="number" value="Default" /> | |
| <option name="presentableId" value="Default" /> | |
| <updated>1523880381711</updated> | |
| </task> | |
| <servers /> | |
| </component> | |
| <component name="ToolWindowManager"> | |
| <frame x="60" y="61" width="1296" height="707" extended-state="0" /> | |
| <editor active="false" /> | |
| <layout> | |
| <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" /> | |
| <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" /> | |
| <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" /> | |
| <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" /> | |
| <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> | |
| <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> | |
| </layout> | |
| </component> | |
| <component name="VcsContentAnnotationSettings"> | |
| <option name="myLimit" value="2678400000" /> | |
| </component> | |
| <component name="XDebuggerManager"> | |
| <breakpoint-manager /> | |
| <watches-manager /> | |
| </component> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import html | |
| import re | |
| def new_quote(): | |
| resp = requests.get("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1") | |
| resp_json = resp.json() #This returns a string enclosed between <p> and </p> tags | |
| m = re.match(r'<p>(.*)</p>', resp_json[0]['content']) | |
| print() | |
| print(html.unescape(m.group(1))) | |
| print('--', resp_json[0]['title']) | |
| print('Find more about',resp_json[0]['title'],'at',resp_json[0]['link'],sep=' ') | |
| print("Hello World and welcome to the Random Quote Machine powered by the Random Quotes API @https://quotesondesign.com/api-v4-0/") | |
| while True: | |
| new_quote() | |
| more = input("Do you want to see another quote? (Y/N): ") | |
| while more not in ('Y','N'): | |
| print("I didn't quite get that. Please try again") | |
| more = input("Do you want to see another quote? (Y/N): ") | |
| if more == 'Y': | |
| print('OK. One more coming up.....') | |
| continue | |
| elif more == 'N': | |
| print('Thanks for using the Random Quote Machine. ') | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment