Python

Python

Explore python code snippets and tutorials

Python

Python3 reverse geocoding with google maps

<p>When you run this code, it will fetch the geocoding results for the provided address and print the JSON representation of those results with proper indentation, making it easy to …

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import json
from pygeocoder import Geocoder

business_geocoder = Geocoder(api_key='my_google_api_key')
results = business_geocoder.geocode("address")

# Get a dictionary representation of the geocoding results
json_result = results.serialize()

# Convert the dictionary to a JSON string with indentation
json_string = json.dumps(json_result, indent=4)

# Print the JSON string
print(json_string)
Python

Python3 Uwsgi

Python3 Uwsgi

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
sudo pip3 install uwsgi
sudo mkdir /etc/uwsgi
sudo mkdir /etc/uwsgi/vassals

sudo nano /etc/systemd/system/emperor.uwsgi.service

Contents of  emperor.uwsgi.service file
---------------------------------------------------------------------------------------
[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

--------------------------------------------------------------------------------

systemctl start emperor.uwsgi.service # start as service

systemctl enable emperor.uwsgi.service  # add service at boot

touch /etc/uwsgi/emperor.ini
sudo nano /etc/uwsgi/emperor.ini


Contents of emperor.ini file  
----------------------------------------------------------------------------------------------

[uwsgi]
emperor = /etc/uwsgi/vassals
vassal-set = processes=8
vassal-set = enable-metrics=1

------------------------------------------------------------------------------------------
Python

Read ics file with python3

Read ics file with python3

python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import urllib.request
from icalendar import Calendar
url = 'your ics url here'
req = urllib.request.Request(url, headers={'User-Agent': "Mozila Firefox"})
con = urllib.request.urlopen(req)
gcal = Calendar.from_ical(con.read())
for component in gcal.walk():
    if component.name == "VEVENT":
        print(component.get('summary'))
        print(component.get('dtstart').dt)
        print(component.get('dtend').dt)
        print(component.get('dtstamp'))
con.close()