Skip to content

Instantly share code, notes, and snippets.

@songxiaofeng1981
Created November 21, 2012 06:53
Show Gist options
  • Save songxiaofeng1981/4123470 to your computer and use it in GitHub Desktop.
Save songxiaofeng1981/4123470 to your computer and use it in GitHub Desktop.
python:get_month_regrex
from dateutil import rrule
from datetime import datetime
import re
def get_dates():
dates = []
dates.append({"start":'201101010000',"end":'201101012359'})
return dates;
def beween_day():
a = '20110101'
b = '20111231'
date_a = []
for dt in rrule.rrule(rrule.DAILY,
dtstart=datetime.strptime(a, '%Y%m%d'),
until=datetime.strptime(b, '%Y%m%d')):
day = dt.strftime('%Y%m%d')
date_s = {'start':day+'0000','end':day+'2359'}
date_a.append(date_s)
return date_a
if __name__ == '__main__' :
# m = re.search('(?<=2011).*(?=\d{2}0000)', '201112290000')
# print m.group(0)
month = 1
months = []
months_all = []
for d in beween_day():
m = re.search('(?<=2011).*(?=\d{6}$)', d['end'])
m_tmp = m.group(0)
m = re.search('.*(?=\d{4}$)', d['end'])
if int(month) == int(m_tmp):
months.append(m.group(0))
else:
month = m_tmp
months = []
months.append(m.group(0))
months_all.append(months)
months_all.append(months)
print (len(months_all))
print (months_all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment