Skip to content

Instantly share code, notes, and snippets.

@bussiere
Created August 13, 2010 13:31
Show Gist options
  • Save bussiere/522891 to your computer and use it in GitHub Desktop.
Save bussiere/522891 to your computer and use it in GitHub Desktop.
#Return a String Calendar formatted
import re, datetime, calendar
def datetoday(day, month, year):
d = day
m = month
y = year
if m < 3:
z = y-1
else:
z = y
dayofweek = ( 23*m//9 + d + 4 + y + z//4 - z//100 + z//400 )
if m >= 3:
dayofweek -= 2
dayofweek = dayofweek%7
return dayofweek
def calendrier():
calendar.setfirstweekday(0)
year = ['Janvier',
'Fevrier',
'Mars',
'Avril',
'Mai',
'Juin',
'Juillet',
'Aout',
'Septembre',
'Octobre',
'Novembre',
'Decembre']
semaine=['Lundi',
'Mardi',
'Mercredi',
'Jeudi',
'Vendredi',
'Samedi',
'Dimanche']
today = datetime.datetime.date(datetime.datetime.now())
current = re.split('-', str(today))
current_no = int(current[1])
current_month = year[current_no-1]
current_day = int(re.sub('\A0', '', current[2]))
current_yr = int(current[0])
month = calendar.monthcalendar(current_yr, current_no)
nweeks = len(month)
jour = semaine[datetoday(current_day,current_no,current_yr)-1]
calendrier = " %s %d %s %d\n L M M J V S D\n"%(jour,current_day,current_month,current_yr)
for m in month :
for days in m :
if days == 0 :
calendrier += " %s "%(" ")
if days < 10 and days != 0:
calendrier += " %d"%days
if days >= 10 :
calendrier += " %d"%days
calendrier += "\n"
return calendrier
print calendrier()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment