SFD:

SFD Countdown Code

####################################################################
### Script based on code written by Matthew Nuzum and available  ###
###                            at                                ###
### https://code.launchpad.net/~newz/ubuntu-website/countdown    ###
###                                                              ###
###    Adapted to support languages, different time zones and    ###
###      different root path between images and symlinks         ###
###                                                              ###
###  Public domain code - take it and do what you want with it!  ###
####################################################################


from datetime import datetime
from datetime import timedelta
import os

PATH_ROOT = '' #this is the path to your base folder which holds all the image files under each language sub-folder
LINK_ROOT = '' # this is the path to your folder on your web server where the public links are available
myzone = '-4' #server timezone

languages = ['en']
#languages = ['en','ru','fr','kh','de','pt','zh_CN','zh_TW','si','fa','es','gl','ko','cs','sr','sh'] #remember to create folders with same name
###################################################################
##           Latest valid time zones taken from                  ##
## http://en.wikipedia.org/wiki/List_of_time_zones_by_UTC_offset ##
###################################################################
timezone = ['-12','-11','-10','-9.30','-9','-8','-7','-6','-5','-4','-3.30','-3','-2','-1','+0','+1','+2','+3','+3.30','+4','+4.30','+5','+5.30','+5.45','+6','+6.30','+7','+8','+8.30','+8.45','+9','+9.30','+10','+10.30','+11','+11.30','+12','+12.45','+13','+14']
d= datetime.now()
sfd = datetime(2016,9,17,3) #SFD Day starts at 3am and not midnight!

if d.year > 2016 or d.month > 9: #if we're past September 2016 no need to run the script
    exit

for zone in timezone:
  # Be carefull: only works with myzone on the hour!
  # Todo: implement calculation for any timezone as the local server time
  h = int(float(zone))-int(myzone)
  m = 0
  if  "." in zone:
    m = int(zone.split(".")[-1])
  adjustment = timedelta(hours = h, minutes = m)
  timeleft = sfd - d - adjustment
  day = timeleft.days + 1 #the logic is that if less than 24 hours there is still 1 day left
  if day < 0:
    day = "00here"
  elif day > 99:
    day = "more"
  elif day < 10:
    day = "0%s" % day
  for lang in languages:
    path = "%s%s/attachments/%s.png" % (PATH_ROOT, lang, day)
    sym = "%s/banner1-UTC%s-%s.png" % (LINK_ROOT, zone, lang)
    if os.path.exists(sym):
        os.remove(sym)
    # update the files mtime in order to solve a caching problem
    os.utime(path, None)
    os.symlink(path, sym)

SFD: CountDown/code (last edited 2016-08-18 08:59:19 by FredericMuller)