Skip to main content

A wrapper for WorldtimeAPI with search functionality.

Project description

Worldtimepy

v0.1.1

Worldtime-py is a Python wrapper for WorldtimeAPI. It is able to search through the endpoints of the API to find the closest location if the exact one could not be found. It reduces the strain and the difficulty of getting the time for the location desired.

WorldtimeAPI is a JSON API for obtaining the current time in, and related data about, a timezone. It gives data suh as the UTC offset, whether that timezone is in Daylight Savings Time (DST), UTC offset, etc.

Installing

This library can be installed by using pip install worldtimepy. Doing so will automatically install all requirements.

Requirements

This library requires you to have requests, unidecode, and countryinfo. All of those can be installed using pip.

Using the wrapper

class worldtime.WorldTime()

This is the main class through which you should interact with the API.

.locations

Has all existing locations from WorldtimeAPI.

return list

.from_ip(ip: str='') -> TimeInfo optional argument: ip

Takes an IP and returns a corresponding TimeInfo object with timezone information for that IP. If no IP is provided, it will use the requesting IP.

return TimeInfo

.find_by_name(name: str) -> list

Takes a string and returns a list of strings for all locations that contain that name.

return list

.search(name: str) -> str

Takes a country name or a city name and tries to find it in the database. It returns a string that can be used by get_location().

Warning: This function iterates through different databases to try and locate the query. It may be slow.

return string

.get_location(location: str) -> object

Takes a proper location taken from search or find_by_name and returns a TimeInfo object.

return TimeInfo

.refresh()

Gathers new data for self.locations.

No return

class timeinfo.TimeInfo(to_get=0, ip: bool=False)

This class takes a location found through one of the other methods and makes an object with information for that timezone. You can use any location from worldtime.WorldTime().locations here.

Alternatively, if you set ip to True, you may provide an IPv4 address on to_get to get time information for that IP. If ip is set to True and nothing is given to to_get, the machine's IP will be used.

Printing or turning this object into a string returns a prettier string containing time information.

2021-06-11 00:14:14.378300 UTC-0700
.result

Full json pulled from the API.

return dict

.week_day

Returns current day of the week.

return int

.year_day

Returns current day of the year.

return int

.week_number

Returns current number of the week of the year.

return int


.datetime

Returns an aware datetime object.

return datetime

.datetime_str

Returns a string version of a datetime object.

return str


.abbreviation

Returns a string representing the abbreviated format of the timezone. E.g. 'PST'

return str


.is_dst

Returns whether timezone is in daylight savings time.

return bool

.dst_offset
.dst_from
.dst_until

.unixtime

Returns a unix like time integer.

return int

.utc

Returns the UTC time..

return str

.utc_offset
.raw_offset

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

worldtimepy-0.1.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

worldtimepy-0.1.1-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file worldtimepy-0.1.1.tar.gz.

File metadata

  • Download URL: worldtimepy-0.1.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

File hashes

Hashes for worldtimepy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5c35a7eb5e20bd4f55f454c7a1a470f66f5f0d8358ec2a9a705d0256ec8198cb
MD5 0b20be1e3e437daf0c10a12606d42c6c
BLAKE2b-256 b046d6232ac06c2db9162afed2d0823e10beeb9d27c57a9c3ae0e7f9a148ad1b

See more details on using hashes here.

File details

Details for the file worldtimepy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: worldtimepy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

File hashes

Hashes for worldtimepy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43295545c6159630fef4402888bd69ce87aace6b43dfb0066ce5ea2d3fdeef44
MD5 28b3b86f826fbb718cdb8d63129870b9
BLAKE2b-256 4be91002758a3338f5b9e08c2b64719fa62e34d6a5195eafd736618b5a095a1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page