Try 30 days of free premium.

Default Airtime to Local Time

Medy wrote 5 years ago: 1

Can someone explain how to make Api call output the "airtime" in my local timezone for episodes ( germany in my case ) ?

http://api.tvmaze.com/singlesearch/shows?q=attack%20on%20titan&embed=episodes

Can I add my country code to the url ?

Do I have to convert all dates ?

Couldnt figure it out from the documentation.

My idea would be converting (though Im not familiar with this either) . What am I missing ?

tnt wrote 5 years ago: 1

At the top of the output you have the network information for the show, which includes the timezone:

network":{"id":281,"name":"NHK","country":{"name":"Japan","code":"JP","timezone":"Asia/Tokyo"}

You could use this to convert the episode airtime to your local timezone. In this case you'll simply need to subtract 7 hours (Asia/Tokyo is GMT +9, CEST is GMT +2). However, different coding languages have different methods to manage TZ conversion.


gazza911 wrote 5 years ago: 1

You have to do it manually - there's 2 ways;

1. Use the network's timezone to convert it

You'd set the offset by setting timezone (in this case, Asia/Tokyo) and then converting it to the named timezone you want.

You'd need to use a library if the language doesn't support it.

Here's some examples:

PHP - DateTime (native, no library needed)
.NET - Noda Time (library)
JavaScript - Moment Timezone (library)

If you let us know what language you're using, it shouldn't be too difficult to find a way of doing it.

2. Use the airstamp

The episode's airstamp is UTC 0.

i.e 2013-04-07T14:30:00+00:00 = 2:30pm 7th April 2013 (UTC 0)

You can then change it to whatever the timezone you're wanting is.

Medy wrote 5 years ago: 1

I see .. so I really need to convert all dates from json if I lets say want a list of episodes with local airtime / my timezone.

Im using python through eventghost ( a windows automation software)...

Doing json requests via requests library .. which is basicly 1-3 line of code .. very straightforward.

this is about the extend I used python so far.

import requests

# TEMPERATURE

r = requests.get('http://yourwesbite.com")

data = r.json()

number = data['state']['temperature']

im confident I could create simple loop in python doing the math for all airtimes, even though I only know beginner javascript.

The thing is Im not familiar with timezones/ converting .. I would need to look up a table with converting time for UTC... so I guess for me it would be ideal if I dont have to worry about which timezone is correct from where im at.

If there is a library that figures this out automatically in python , that would be best.

Only constraint is probaly the eventghost software itself ... since from what ive read it doesnt support the latest version of python... this maybe a problem finding a working library.

Anyway good to know this is how its done now.

I feel like a little hint about how to convert airtime should be mentioned in the doc somehow , would be cool.

Because looking through the api doc .... I found there is a schedule endpoint , which allows you to put a country code and it will output all episodes that realase that day

Example: http://api.tvmaze.com/schedule?country=US&date=2014-12-01

in the correct local time. So it really confused me why I cant do the same with the episode endpoint ? It makes no sense to me , that this isnt an option. Which made me question that converting is maybe the wrong aproach.

smth like :

http://api.tvmaze.com/singlesearch/shows?q=attack%20on%20titan&embed=episodes&country=DE

Medy wrote 5 years ago: 1

Let me get this right : Im looking at another app ( TVtime)

that tell me next episode of overlord comes out tommorow 15:00 in my local time.

Looking at the tvmaze api it says

airtime : 22:30

airstamp : "2018-08-21T13:30:00+00:00"

runtime : 30

countryname"Japan"

code"JP"

timezone"Asia/Tokyo"

since im in germany utc+9 ( 9 hour differnce)

I would need to calculate 22:30 - 9 = 13:30

since my local time "berlin" is gmt +2 = 15:30 ( 30 min plus ) ?

idk if this is correct though ?

.

Another example Steins gate 0 :

same timezone , same app =

airtime = "01:35"

tvtime app says it will air in my local time 18 : 30

01:35 - 9 = 16:35

+ gmt 2 = 18:35 --> correct

.

Another example How to not summon a demon Lord :

airtime : 21:30

app says 14 : 30

21:30 - 9 = 12:30

+ gmt 2 = 14:30 --> correct

ok maybe this calc is not entirely correct or they have different data ?

wikipedia says they use tvdb database ... will take a look at their dates.

Medy wrote 5 years ago: 1

tvdb have different air times sometimes for whatever reason. but mostlly identical. ... I wrote all this down so if someone reads this it might clear up their confusion as well.

according to forum post their time dates are not meant to be used ( even though they display the local air time of where the series is originated at, they dont provide the country code .. so you cant do calculation based on that. so tv maze has advantage here if you plan on using times for a guide or smth.

this is good website to see the conversion :https://www.worldtimebuddy.com/

I will look into library and post some sample code for python later.


david wrote 5 years ago: 1

Germany is not UTC+9, but +2.

Medy wrote 5 years ago: 1

Ok here a little script I wrote:

Im using request libray + pytz library for (World Times)

1. Http Get Json
2. Acces field 'timezone' from json . It will return ( "Asia/Tokyo" ) from the url I used here

3. Convert String 'Asia/Tokyo' into your localtime

Here is my test code that converts your local

import requests

from datetime import datetime

from pytz import timezone

# Request JSON

# Anime Series ( Japan ) - How to not summon a demon Lord

# http://api.tvmaze.com/singlesearch/shows?q=How%20to%20not%20summon%20a%20demon%20Lord%20&embed=episodes

r = requests.get('http://api.tvmaze.com/singlesearch/shows?q=How%20to%20not%20summon%20a%20demon%20Lord%20&embed=episodes')

data = r.json()

# wil return : "Asia/Tokyo"

zone_from_tvmaze = data['network']['country']['timezone']

print zone_from_tvmaze

#Format

fmt = "%Y-%m-%d %H:%M:%S %Z%z"

# Current time in UTC

now_utc = datetime.now(timezone('UTC'))

print now_utc.strftime(fmt)

# Convert to Asia/Tokyo time zone

now_zone = now_utc.astimezone(timezone(zone_from_tvmaze))

print now_zone.strftime(fmt)

# Convert to Europe/Berlin time zone

now_berlin = now_zone.astimezone(timezone('Europe/Berlin'))

print now_berlin.strftime(fmt)

Output :

Asia/Tokyo

2018-08-20 07:36:09 UTC+0000 <<< local time converted to UTC

2018-08-20 16:36:09 JST+0900 <<<< converted UTC to 'Asia/Tokyo' time

2018-08-20 09:36:09 CEST+0200 <<< 'Asia/Tokyo' to 'Europe/Berlin' <<< the stuff you want

Medy wrote 5 years ago: 1

david wrote:
Germany is not UTC+9, but +2.

True... I wrote nonesense there ...what I meant is 9 hour difference to my local time ...

thx to anyone helping me.

Try 30 days of free premium.