Skip to content

Instantly share code, notes, and snippets.

@SteveMcGrath
Last active August 29, 2015 14:07
Show Gist options
  • Save SteveMcGrath/0cd65793df76733915a7 to your computer and use it in GitHub Desktop.
Save SteveMcGrath/0cd65793df76733915a7 to your computer and use it in GitHub Desktop.
Determine the build week date of Cisco Equipment
from datetime import date, timedelta
import calendar
def builddate(serial):
'''
Returns a date object of the manufactured date.
'''
# The serial format is LLLYYWWSSSS where YY and WW denote the build week.
# YY -- Decimal number where 00 denotes 1996 as the starting year.
# WW -- Decimal number of the week of the year it was built.
year = 1996 + int(serial[3:5])
week = timedelta(days=7 * int(serial[5:7]))
mdate = date(year, 1, 1) + week
return mdate
if __name__ == '__main__':
serial = raw_input('Enter Cisco Serial Number : ')
mdate = builddate(serial)
cal = calendar.month(mdate.year, mdate.month).split('\n')[2:-1]
weekno = 0
for week in cal:
if str(mdate.day) in week:
weekno = cal.index(week)
prettymap = {1: 'st', 2: 'nd', 3: 'rd', 4: 'th', 5: 'th'}
print '\n%d%s week in %s\n' % (weekno, prettymap[weekno], mdate.strftime('%B, %Y'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment