TOOLSP
"
WELCOME !

Please ! Use [CODE] tags for your LINKS and CODE.
Favor usar balisas [CODE] para sus vínculos y código.
Merci d'utiliser les balises [CODE] pour vos liens et code.

[code]http://Thank.you[/code]
"
*** GITHUB ***
.
.
URL Resolver [GIT]
.
.
.
.
Jx Update [REDIRECT]
.
.
*** Associated ***
.
Pastebin Your list online
.
mediafire Upload Files
.
imgur Upload Pics
lyngsat TV logos collection
transparent .png
.
http://hola.org free? VPN
Hola.apk free? VPN App.
.
hidester- free Proxy
.
webgrabplus EPG - Eng
xmltv EPG - Fr
kazer EPG - Fr
.
.wordreference Traduction
.
mail.com (fast sign-in)
.
.
Latest topics
» Regex for my favori serie
Sun 24 Sep - 21:12 by beezlo

» help regex
Fri 22 Sep - 21:08 by mickydoo

» I need i little help please!
Wed 20 Sep - 18:24 by jujuuj

» some help with vaughn or ustream .TV
Wed 20 Sep - 0:56 by adrianhn

» Xbmc tool box / Xbmc gui (Kodi)
Mon 18 Sep - 18:16 by oxus

» how to play this in kodi
Mon 11 Sep - 8:25 by retrorat1

» Where to put your list
Sun 10 Sep - 14:29 by oxus

FRIENDS / PARTNERS

forum

créer un forum


LOCAL TIME : How to subtract 1 hour from the grabbed time ?

View previous topic View next topic Go down

LOCAL TIME : How to subtract 1 hour from the grabbed time ?

Post by Admin on Sun 16 Apr - 15:39

Originally Posted by JonnyB (in tvaddons) :

Hi,
How can I subtract 1 hour in a regex?

Example:
Some capturing group captures this time: 20:15, but in my local time is at 19:15.

Is there a way to subtract in 1 hour in this capturing group?
Thanks

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

Answer of twogun :

Quick python lesson using your question.  You want to subtract 1 hour from the grabbed time.  Or from your specific example 20:15 --> 19:15

So lets say that 'time' is the data you grabbed from the website

Code:
time = '20:15'   # in your real code it will probaly be something like time = [makelist.param1]

localtime = int(time[:-3]) - 1
# in the above line
# int() coverts the string into an integer.  This allows it to be used in math functions.
# [:-3] removes 3 characters from the end of the varible.  So we get just 20 instead of the whole value 20:15
# and simple enough ' - 1 ' subtracts 1 from 20.  20 --> 19.  So localtime equals 19 (an integer)


localtime = str(localtime) + time[2:]
# the above line converts localtime back to a string and combine '19' with the remaining time ':15'
# str() converts the varible to a string
# [2:] removes the first 2 characters from the varible time:  19:15 --> :15
# addition of the 2 comine the strings  '19' + ':15' = '19:15'

now you can use the value how ever you need for example return it to be used by your makelist or info tags
return localtime

I hope that helps

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

THANKS !

Admin

Messages : 33
Date d'inscription : 2017-03-28

View user profile http://toolsp.forumactif.com

Back to top Go down

Update / bug fixes

Post by twogun on Sun 16 Apr - 23:56

When I originally wrote this I forgot to compensate for cases where the var localtime would be greater then 24 or less the 1.

Also the original code require this format HH:MM.  This means that entry of H:MM would cause an error.  So  1:15 would need a leading zero like this:  01:15.  I've made a small change that allows the code to receive  both 1:15 and 01:15 as input.

I've included a 24 hour and 12 hour version

24 hour:
Code:

def GetLSProData(page_data,Cookie_Jar,m):
 time = '5:15'
 time = time.zfill(5)  #  insure the var time is 5 spaces by adding leading zero

 localtime = int(time[:-3]) - 1

 # if the hour is greater then 24 subtract 24 from it
 if localtime > 24:
     localtime -= 24

# if the hour is less then 1 add 24 to it.
 if localtime < 1:
     localtime += 24

 localtime = str(localtime) + time[2:]
 return localtime
# return localtime.zfill(5) #  use this if you need leading zeros  Example: 05:15pm instead of 5:15pm

12 hour:
Code:
def GetLSProData(page_data,Cookie_Jar,m):
 time = '2:15'
 time = time.zfill(5)   #  insure the var time is 5 spaces by adding leading zero

 localtime = int(time[:-3]) - 1

# if the hour is greater then 12 subtract 12
 if localtime > 12:
     localtime -= 12

# if the hour is less then 12 add 12 to it.
 if localtime < 1:
     localtime += 12

 localtime = str(localtime) + time[2:]
 return localtime
# return localtime.zfill(5)  # use this if you need leading zeros  Example: 05:15pm instead of 5:15pm
avatar
twogun

Messages : 33
Date d'inscription : 2017-04-03

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum