-
Notifications
You must be signed in to change notification settings - Fork 0
/
gettz
executable file
·42 lines (31 loc) · 888 Bytes
/
gettz
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
#!/usr/bin/env python3
# Author: Jan Larres <[email protected]>
# License: MIT/X11
import argparse
import logging
import sys
import requests
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.WARNING)
log = logging.getLogger(__name__)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Print timezone based on current IP address"
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
default=False,
help="increase output verbosity",
)
return parser.parse_args()
def main(args: argparse.Namespace) -> int:
if args.verbose:
log.setLevel(logging.DEBUG)
r = requests.get("https://ipinfo.io/json").json()
log.debug(r)
tz = r["timezone"]
print(tz)
return 0
if __name__ == "__main__":
sys.exit(main(parse_args()))