Skip to content

Commit

Permalink
switched to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannicoppola committed Mar 30, 2022
1 parent ca4cd56 commit 3b4ca78
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 167 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
*.pyc
__pycache__
/source/lib
Binary file added source/alfred-almanac1-1.alfredworkflow
Binary file not shown.
30 changes: 13 additions & 17 deletions source/almanac.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
#import requests
import json
import sys
import urllib.request
import urllib.parse
import requests
from datetime import datetime
import datetime as date2
import re, os, time


from config import LOCATION, FORMATSTRING, SPECIAL_DAY

FORMATSTRING = FORMATSTRING+"--%Z--" #adding local timezone
FORMATSTRING = f'"{FORMATSTRING}"' #enclosing in quotes
#FORMATSTRING = f'"{FORMATSTRING}"' #enclosing in quotes


def log(s, *args):
Expand All @@ -31,26 +29,24 @@ def get_weather(location):


myURL= "http://wttr.in/"
params ="format="+ urllib.parse.quote(FORMATSTRING,safe='%(),')
paramsJ = "format=j1"

payload = {'format': FORMATSTRING}
payload_j = {'format': "j1"}
#paramsJ = "format=j1"
location = location.strip()
location=re.sub(" ", '+', location)


myURL= "http://wttr.in/" + location + "?" + params

with urllib.request.urlopen(myURL) as response:
myData = json.load(response)
resp = requests.get(f"http://wttr.in/{loc}", params=payload)
myData = resp.text.strip()
log (myData)

#fetching also the JSON output for extra information
myURL= "http://wttr.in/" + location + "?" + paramsJ

with urllib.request.urlopen(myURL) as response:
myDataJ = json.load(response)

resp_j = requests.get(f"http://wttr.in/{loc}", params=payload_j)

myLocation = myDataJ['nearest_area'][0]['areaName'][0]['value'] #getting the location from the output
myResults = (resp_j.json())
myLocation = myResults['nearest_area'][0]['areaName'][0]['value'] #getting the location from the output


# extracting timezone
timeZonePattern="--(.*?)--"

Expand Down
148 changes: 0 additions & 148 deletions source/almanac_requests.py

This file was deleted.

4 changes: 2 additions & 2 deletions source/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<key>script</key>
<string>export PATH=/opt/homebrew/bin:/usr/local/bin:$PATH
export PYTHONPATH="$PWD/lib"
python3 almanac_requests.py $1 "${LOCATION}"</string>
python3 almanac.py $1 "${LOCATION}"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -346,7 +346,7 @@ python3 almanac_requests.py $1 "${LOCATION}"</string>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.0.1</string>
<string>1.1</string>
<key>webaddress</key>
<string>https://github.com/giovannicoppola/alfred-almanac</string>
</dict>
Expand Down

0 comments on commit 3b4ca78

Please sign in to comment.