Skip to content

Commit

Permalink
Merge pull request #1 from giovannicoppola/withRequests
Browse files Browse the repository at this point in the history
With requests
  • Loading branch information
giovannicoppola committed Mar 30, 2022
2 parents e796c51 + 96231a2 commit ca4cd56
Show file tree
Hide file tree
Showing 120 changed files with 39,538 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
src="https://img.shields.io/github/downloads/giovannicoppola/alfred-almanac/total?color=purple&label=Downloads"><br/>
</a>


<!-- MarkdownTOC autolink="true" bracket="round" depth="3" autoanchor="true" -->

- [Setting up](#setting-up)
Expand Down
Binary file added alfred almanac_requests.alfredworkflow
Binary file not shown.
148 changes: 148 additions & 0 deletions source/almanac_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/usr/bin/env python3

## a script to get a one-liner from wttr
# Wednesday, July 21, 2021, 10:42 AM
# Tuesday, March 1, 2022, 8:51 AM new version without requests

#import requests
import json
import sys
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


def log(s, *args):
if args:
s = s % args
print(s, file=sys.stderr)



def get_weather(location):


myURL= "http://wttr.in/"
#params ="format="+ urllib.parse.quote(FORMATSTRING,safe='%(),')
payload = {'format': FORMATSTRING}
payload_j = {'format': "j1"}
#paramsJ = "format=j1"
location = location.strip()
location=re.sub(" ", '+', location)


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

#fetching also the JSON output for extra information
resp_j = requests.get(f"http://wttr.in/{loc}", params=payload_j)
#myURL= "http://wttr.in/" + location + "?" + paramsJ

myResults = (resp_j.json())
myLocation = myResults['nearest_area'][0]['areaName'][0]['value'] #getting the location from the output
#with urllib.request.urlopen(myURL) as response:
# myDataJ = json.load(response)


#myLocation = myDataJ['nearest_area'][0]['areaName'][0]['value'] #getting the location from the output


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

myTimeZone = re.search(timeZonePattern, myData).group(1)

#print (myTimeZone)
myData=re.sub(timeZonePattern, '', myData)

myWeatherString = myLocation + \
" – " + myData.strip()

#getting date and time in the corresponding timezone
os.environ['TZ'] = myTimeZone
time.tzset()
myLocalTime=time.asctime()
log (myLocalTime)


return (myWeatherString,myLocalTime)


def almanac ():
today = datetime.now()
todayStandard = today.strftime("%Y-%m-%d %a %-I:%M%p")
todayMonth = today.month
todayHour = today.hour

todayQuarter = (todayMonth-1)//3 + 1
currentYear = today.year

day_of_year = datetime.now().timetuple().tm_yday # from https://stackoverflow.com/questions/620305/convert-year-month-day-to-day-of-year-in-python
year_week = date2.date.today().isocalendar()[1]

Yend = datetime(currentYear,12,31)
days_to_Yend = Yend - today


## Special Day
SD_month, SD_day = SPECIAL_DAY.split('-')
currentSD = datetime(currentYear,int(SD_month),int(SD_day))
dateDiff = currentSD - today

if dateDiff.days>0: #SD is in the future
pastSD = datetime(currentYear-1,int(SD_month),int(SD_day))
nextSD = currentSD
else:
pastSD = currentSD
nextSD = datetime(currentYear+1,int(SD_month),int(SD_day))

days_fromSD = (today - pastSD).days
days_toSD = (nextSD - today).days

myAlmanacString = "\nW"+str(year_week)+"Q"+str(todayQuarter)+" – "+ str(day_of_year) + " ➡️ " + str(days_to_Yend.days) + \
" – " + str(days_fromSD) + " ❇️ " + str(days_toSD)


if todayHour > 12:
myIcon = "icons/moon.png"
else:
myIcon = "icons/sun.png"
return (myAlmanacString,myIcon)



result = {"items": []}
mylocation = LOCATION
if sys.argv[1] == '':
mylocation = LOCATION
else:
mylocation = sys.argv[1]

myAlmanac,myIcon = almanac()

locations = mylocation.split(",")
for loc in locations:
myOutput,myLocalTime= get_weather(loc)
myFinalString = myOutput + " " + myLocalTime + myAlmanac
result["items"].append({
"title": myFinalString,
'subtitle': "↩️ copy to clipboard, ^↩️ large text, ⇧↩️ open in browser",

"icon": {
"path": myIcon
},
'arg': (myFinalString + ";;;" + f"http://wttr.in/{loc}")
})

print (json.dumps(result))

5 changes: 3 additions & 2 deletions source/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
<string>one moment while I retrieve the weather from wttr.in</string>
<key>script</key>
<string>export PATH=/opt/homebrew/bin:/usr/local/bin:$PATH
python3 almanac.py $1 "${LOCATION}"</string>
export PYTHONPATH="$PWD/lib"
python3 almanac_requests.py $1 "${LOCATION}"</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -345,7 +346,7 @@ python3 almanac.py $1 "${LOCATION}"</string>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.0</string>
<string>1.0.1</string>
<key>webaddress</key>
<string>https://github.com/giovannicoppola/alfred-almanac</string>
</dict>
Expand Down
8 changes: 8 additions & 0 deletions source/lib/bin/normalizer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/local/opt/[email protected]/bin/python3.9
# -*- coding: utf-8 -*-
import re
import sys
from charset_normalizer.cli.normalizer import cli_detect
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(cli_detect())
1 change: 1 addition & 0 deletions source/lib/certifi-2021.10.8.dist-info/INSTALLER
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
21 changes: 21 additions & 0 deletions source/lib/certifi-2021.10.8.dist-info/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
This package contains a modified version of ca-bundle.crt:

ca-bundle.crt -- Bundle of CA Root Certificates

Certificate data from Mozilla as of: Thu Nov 3 19:04:19 2011#
This is a bundle of X.509 certificates of public Certificate Authorities
(CA). These were automatically extracted from Mozilla's root certificates
file (certdata.txt). This file can be found in the mozilla source tree:
http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1#
It contains the certificates in PEM format and therefore
can be directly used with curl / libcurl / php_curl, or with
an Apache+mod_ssl webserver for SSL client authentication.
Just configure this file as the SSLCACertificateFile.#

***** BEGIN LICENSE BLOCK *****
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
one at http://mozilla.org/MPL/2.0/.

***** END LICENSE BLOCK *****
@(#) $RCSfile: certdata.txt,v $ $Revision: 1.80 $ $Date: 2011/11/03 15:11:58 $
83 changes: 83 additions & 0 deletions source/lib/certifi-2021.10.8.dist-info/METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Metadata-Version: 2.1
Name: certifi
Version: 2021.10.8
Summary: Python package for providing Mozilla's CA Bundle.
Home-page: https://certifiio.readthedocs.io/en/latest/
Author: Kenneth Reitz
Author-email: [email protected]
License: MPL-2.0
Project-URL: Documentation, https://certifiio.readthedocs.io/en/latest/
Project-URL: Source, https://github.com/certifi/python-certifi
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9

Certifi: Python SSL Certificates
================================

`Certifi`_ provides Mozilla's carefully curated collection of Root Certificates for
validating the trustworthiness of SSL certificates while verifying the identity
of TLS hosts. It has been extracted from the `Requests`_ project.

Installation
------------

``certifi`` is available on PyPI. Simply install it with ``pip``::

$ pip install certifi

Usage
-----

To reference the installed certificate authority (CA) bundle, you can use the
built-in function::

>>> import certifi

>>> certifi.where()
'/usr/local/lib/python3.7/site-packages/certifi/cacert.pem'

Or from the command line::

$ python -m certifi
/usr/local/lib/python3.7/site-packages/certifi/cacert.pem

Enjoy!

1024-bit Root Certificates
~~~~~~~~~~~~~~~~~~~~~~~~~~

Browsers and certificate authorities have concluded that 1024-bit keys are
unacceptably weak for certificates, particularly root certificates. For this
reason, Mozilla has removed any weak (i.e. 1024-bit key) certificate from its
bundle, replacing it with an equivalent strong (i.e. 2048-bit or greater key)
certificate from the same CA. Because Mozilla removed these certificates from
its bundle, ``certifi`` removed them as well.

In previous versions, ``certifi`` provided the ``certifi.old_where()`` function
to intentionally re-add the 1024-bit roots back into your bundle. This was not
recommended in production and therefore was removed at the end of 2018.

.. _`Certifi`: https://certifiio.readthedocs.io/en/latest/
.. _`Requests`: https://requests.readthedocs.io/en/master/

Addition/Removal of Certificates
--------------------------------

Certifi does not support any addition/removal or other modification of the
CA trust store content. This project is intended to provide a reliable and
highly portable root of trust to python deployments. Look to upstream projects
for methods to use alternate trust.


13 changes: 13 additions & 0 deletions source/lib/certifi-2021.10.8.dist-info/RECORD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
certifi-2021.10.8.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
certifi-2021.10.8.dist-info/LICENSE,sha256=vp2C82ES-Hp_HXTs1Ih-FGe7roh4qEAEoAEXseR1o-I,1049
certifi-2021.10.8.dist-info/METADATA,sha256=iB_zbT1uX_8_NC7iGv0YEB-9b3idhQwHrFTSq8R1kD8,2994
certifi-2021.10.8.dist-info/RECORD,,
certifi-2021.10.8.dist-info/WHEEL,sha256=ADKeyaGyKF5DwBNE0sRE5pvW-bSkFMJfBuhzZ3rceP4,110
certifi-2021.10.8.dist-info/top_level.txt,sha256=KMu4vUCfsjLrkPbSNdgdekS-pVJzBAJFO__nI8NF6-U,8
certifi/__init__.py,sha256=xWdRgntT3j1V95zkRipGOg_A1UfEju2FcpujhysZLRI,62
certifi/__main__.py,sha256=xBBoj905TUWBLRGANOcf7oi6e-3dMP4cEoG9OyMs11g,243
certifi/__pycache__/__init__.cpython-39.pyc,,
certifi/__pycache__/__main__.cpython-39.pyc,,
certifi/__pycache__/core.cpython-39.pyc,,
certifi/cacert.pem,sha256=-og4Keu4zSpgL5shwfhd4kz0eUnVILzrGCi0zRy2kGw,265969
certifi/core.py,sha256=V0uyxKOYdz6ulDSusclrLmjbPgOXsD0BnEf0SQ7OnoE,2303
6 changes: 6 additions & 0 deletions source/lib/certifi-2021.10.8.dist-info/WHEEL
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.35.1)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any

1 change: 1 addition & 0 deletions source/lib/certifi-2021.10.8.dist-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
certifi
3 changes: 3 additions & 0 deletions source/lib/certifi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .core import contents, where

__version__ = "2021.10.08"
12 changes: 12 additions & 0 deletions source/lib/certifi/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import argparse

from certifi import contents, where

parser = argparse.ArgumentParser()
parser.add_argument("-c", "--contents", action="store_true")
args = parser.parse_args()

if args.contents:
print(contents())
else:
print(where())
Loading

0 comments on commit ca4cd56

Please sign in to comment.