def trans_data(cls, source_data): _ = TrendBase.trans_data(source_data) _['name'] = SolarCalendar.recent(_['buy_date'])['name'] bd = LunarDate.fromSolarDate(_['buy_date'].year, _['buy_date'].month, _['buy_date'].day) sd = LunarDate.fromSolarDate(_['buy_date'].year, _['buy_date'].month, _['buy_date'].day) _['buy_tradate'] = '{}-{:02d}-{:02d}'.format(bd.year, bd.month, bd.day) _['sell_tradate'] = '{}-{:02d}-{:02d}'.format(sd.year, sd.month, sd.day) return _
def post(self): user = users.get_current_user() if user: pass else: self.redirect(users.create_login_url(self.request.uri)) msg_job_queue_name= DEFAULT_MESSAGING_JOB_NAME msg_job = MessagingJob(parent=messagingJob_key(msg_job_queue_name)) msg_job.owner = users.get_current_user() msg_job.note = self.request.get('content') if self.request.get('date_type') == 'lunar': try: msg_job.date = LunarDate(int(self.request.get('year')), int(self.request.get('month')), int(self.request.get('day'))).toSolarDate() except ValueError: self.redirect('/?msg=invalid_date') return else: try: msg_job.date = date(int(self.request.get('year')), int(self.request.get('month')), int(self.request.get('day'))) LunarDate.fromSolarDate(msg_job.date.year, msg_job.date.month, msg_job.date.day).toSolarDate() except ValueError: self.redirect('/?msg=invalid_date') return lunarDate=LunarDate.fromSolarDate(msg_job.date.year,msg_job.date.month,msg_job.date.day) msg_job.lunar_month = lunarDate.month msg_job.lunar_day = lunarDate.day base_messaging_jobs_query = MessagingJob.query( ancestor=messagingJob_key(DEFAULT_MESSAGING_JOB_NAME)) messaging_jobs_query_by_user = base_messaging_jobs_query.filter( MessagingJob.owner == user) if messaging_jobs_query_by_user.count() >= MAX_ENTRIES_PER_USER: self.redirect('/?msg=exceed_user_quota') return messaging_jobs_query_by_date = base_messaging_jobs_query.filter( MessagingJob.lunar_month == msg_job.lunar_month).filter( MessagingJob.lunar_day == msg_job.lunar_day) if messaging_jobs_query_by_date.count() >= MAX_ENTRIES_PER_DAY: self.redirect('/?msg=exceed_daily_quota') return msg_job.put() self.redirect('/')
def lunar_date(date): ''' Return lunar date accodring to given date Its format should be 1985-09-06 or 1985/09/06 raise Value error if date is not correct ''' if '-' in date: split_date = date.split('-') elif '/' in date: split_date = date.split('/') else: raise ValueError, "%s Not as 1985-09-06 or 1985/09/06" % date if len(split_date) != 3: raise ValueError, "%s Not as 1985-09-06 or 1985/09/06" % date year = int(split_date[0]) month = int(split_date[1]) day = int(split_date[2]) if year < 1900 or year > 2049: raise ValueError, "Year should in [1900, 2049]" date = datetime(year, month, day) date = LunarDate.fromSolarDate(year, month, day) day1=[u"初", u"十", u"廿", u"三"] day2=[u"十", u"一", u"二", u"三", u"四", u"五", u"六", u"七", u"八", u"九"] month=day2[:] month[1] = u"正" month.extend([u"十", u"冬", u"腊"]) return u"%s年%s月%s%s" % (date.year, month[date.month], day1[date.day/10], day2[date.day%10])
def getTerm(date=None, seazon=None): # getTerm(year, seazon): # getTerm(2014, 0): 2014 Spring # getTerm(2014, 1): 2014 Autumn # getTerm([date]): # getTerm('2014-09-01') if date is None: date = getDateCN() if seazon is not None: year = date else: year, month, day = date.split('-') year = int(year) month = int(month) day = int(day) yearLunar = LunarDate.fromSolarDate(year, month, day).year if month < 8: if yearLunar == year: seazon = 0 else: seazon = 1 else: seazon = 1 year = yearLunar return str((year - 2009) * 2 + seazon)
def process_workbook(workbook): s = workbook.sheet_by_index(0) print(s.name) out_book = Workbook() sheet1 = out_book.add_sheet("Sheet 1") cells = s.row(0) for i in range(3): sheet1.write(0, i, cells[i].value) sheet1.write(0, 3, u"阴历") for i in range(5): sheet1.write(0, 4 + i, unicode(2014 + i) + u" 阳历") for row in range(1, s.nrows): for col in range(3): value = s.cell(row, col).value sheet1.write(row, col, value) value = s.cell(row, 2).value valstr = str(int(value)) y = valstr[:4] m = valstr[4:6] d = valstr[6:8] #print(valstr) #print(y, m, d) y = int(y) m = int(m) d = int(d) try: lunar_date = LunarDate.fromSolarDate(y, m, d) sheet1.write( row, 3, u"{}-{}-{}".format(lunar_date.year, lunar_date.month, lunar_date.day)) for i in range(5): lunar_date.year = 2014 + i try: d = lunar_date.toSolarDate() sheet1.write(row, 4 + i, u"{}-{}-{}".format(d.year, d.month, d.day)) except Exception as e: print(e) print(u"错误的日期(1):" + valstr) print(lunar_date) sheet1.write(row, 4 + i, u"错误") except Exception as e: print(e) print(u"错误的日期(2):" + valstr) sheet1.write(row, 3, u"错误的日期" + valstr) return out_book
def isHoliday(self, date): y = date.getYear() m = date.getMonth() d = date.getDay() lDay = LunarDate.fromSolarDate(y, m, d) lm = lDay.month ld = lDay.day flag = ((m == 1) and (d == 1)) \ or ((m == 3) and (d == 1)) \ or (d == 5 and m == 4 and y <= 2005) \ or(d == 1 and m == 5) \ or(d == 5 and m == 5) \ or (d == 6 and m == 6) \ or (d == 17 and m == 7 and y <= 2007) \ or(d == 15 and m == 8) \ or (d == 3 and m == 10) \ or ((m == 10) and (d == 9) and (y >= 2013)) \ or ((m == 12) and (d == 25)) \ or ((lm == 12) and (ld == 31))\ or ((lm == 1) and (ld == 1))\ or ((lm == 1) and (ld == 2))\ or ((lm == 4) and (ld == 8))\ or ((lm == 8) and (ld == 14))\ or ((lm == 8) and (ld == 15))\ or ((lm == 8) and (ld == 16))\ or (d == 15 and m == 4 and y == 2004)\ or (d == 31 and m == 5 and y == 2006)\ or (d == 19 and m == 12 and y == 2007)\ or (d == 9 and m == 4 and y == 2008)\ or (d == 2 and m == 6 and y == 2010)\ or (d == 11 and m == 4 and y == 2012)\ or (d == 19 and m == 12 and y == 2012)\ or (d == 4 and m == 6 and y == 2014)\ or (d == 13 and m == 4 and y == 2016)\ or (d == 20 and m == 12 and y == 2017)\ or (d == 18 and m == 2 and y == 2015) \ or (d == 10 and m == 9 and y == 2014) if self.isWeekend(date) or flag : return True else : return False
def isHoliday(self, date): y = date.getYear() m = date.getMonth() d = date.getDay() lDay = LunarDate.fromSolarDate(y, m, d) lm = lDay.month ld = lDay.day flag = ((m == 1) and (d == 1)) \ or ((m == 3) and (d == 1)) \ or (d == 5 and m == 4 and y <= 2005) \ or(d == 1 and m == 5) \ or(d == 5 and m == 5) \ or (d == 6 and m == 6) \ or (d == 17 and m == 7 and y <= 2007) \ or(d == 15 and m == 8) \ or (d == 3 and m == 10) \ or ((m == 10) and (d == 9) and (y >= 2013)) \ or ((m == 12) and (d == 25)) \ or ((lm == 12) and (ld == 31))\ or ((lm == 1) and (ld == 1))\ or ((lm == 1) and (ld == 2))\ or ((lm == 4) and (ld == 8))\ or ((lm == 8) and (ld == 14))\ or ((lm == 8) and (ld == 15))\ or ((lm == 8) and (ld == 16))\ or (d == 15 and m == 4 and y == 2004)\ or (d == 31 and m == 5 and y == 2006)\ or (d == 19 and m == 12 and y == 2007)\ or (d == 9 and m == 4 and y == 2008)\ or (d == 2 and m == 6 and y == 2010)\ or (d == 11 and m == 4 and y == 2012)\ or (d == 19 and m == 12 and y == 2012)\ or (d == 4 and m == 6 and y == 2014)\ or (d == 13 and m == 4 and y == 2016)\ or (d == 20 and m == 12 and y == 2017)\ or (d == 18 and m == 2 and y == 2015) \ or (d == 10 and m == 9 and y == 2014) if self.isWeekend(date) or flag: return True else: return False
periods = ['2020'] flags = ['after2', 'lock2'] #'before',,'after' locations = ['USA'] #'Russia','Germany','China','Brazil','SA','India' lock_year = 2020 output_dir = '/storage/qliu6/trmm/1998_2017_merge/results/OMI/period/' for location in locations: if location == 'China': lock_month = 1 lock_day = 25 reopen_month = 4 reopen_day = 9 end_month = 6 end_day = 30 lock_doy = doy(lock_year, lock_month, lock_day) lunar_lock_date = LunarDate.fromSolarDate(int(lock_year), int(lock_month), int(lock_day)) lstart = LunarDate(lunar_lock_date.year, 1, 1) ldoy_lock = (lunar_lock_date - lstart).days + 1 reopen_doy = doy(lock_year, reopen_month, reopen_day) lunar_reopen_date = LunarDate.fromSolarDate( int(lock_year), int(reopen_month), int(reopen_day)) ldoy_reopen = (lunar_reopen_date - lstart).days + 1 print(ldoy_reopen) end_doy = doy(lock_year, end_month, end_day) lunar_end_date = LunarDate.fromSolarDate(int(lock_year), int(end_month), int(end_day)) ldoy_end = (lunar_end_date - lstart).days + 1
def getLunarDate(self): ld = LunarDate.fromSolarDate(self.date.year, self.date.month,self.date.day) return ld
"雷泽归妹":"归妹,天地之大义也。天地不交,而万物不兴。归妹,人之终始也。说以动,所归妹也。征凶,位不当也。无攸利,柔乘刚也。", "雷火丰":"丰,大也。明以动,故丰。王假之,尚大也。勿忧宜日中,宜照天下也。日中则昃,月盈则食,天地盈虚,与时消息,而况于人乎,况于鬼神乎?", "火山旅":"旅,小亨,柔得中乎外,而顺乎刚,止而丽乎明,是以小亨旅贞吉也。旅之时义大矣哉。", "风风巽":"重巽以申命,刚巽乎中正而志行。柔皆顺乎刚,是以小亨,利有攸往,利见大人。", "泽泽兑":"兑,说也。刚中而柔外,说以利贞,是以顺乎天,而应乎人。说以先民,民忘其劳。说以犯难,民忘其死。兑之大,民劝矣哉。", "风水涣":"涣亨,刚来而不穷,柔得位乎外,而上同。王假有庙,王乃在中也。利涉大川,乘木有功也。", "水泽节":"节亨,刚柔分而刚得中。苦节不可贞,其道穷也。说以行险,当位以节,中正以通。天地节,而四时成。节以制度,不伤财,不害民。", "风泽中孚":"中孚,柔在内而刚得中,说而巽,孚乃化邦也。豚鱼吉,信及豚鱼也。利涉大川,乘木舟虚也。中孚以利贞,乃应乎天也。", "雷山小过":"小过,小者过而亨也。过以利贞,与时行也。柔得中,是以小事吉也。刚失位而不中,是以不可大事也。有飞鸟之象焉,飞鸟遗之音,不宜上宜下大吉,上逆而下顺也。", "水火既济":"既济亨,小者亨也。利贞,刚柔正而位当也。初吉,柔得中也。终止则乱,其道穷也。", "火水未济":"未济亨,柔得中也。小狐汔济,未出中也。濡其尾,无攸利,不续终也。虽不当位,刚柔应也。" } timestr=time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())) timelist=timestr.split('-') lunar=LunarDate.fromSolarDate(int(timelist[0]),int(timelist[1]),int(timelist[2])) lunar_year=((lunar.year-2000+6)%12) and ((lunar.year-2000+6)%12) or 12 lunar_month=lunar.month lunar_day=lunar.day lunar_hour=bool(((int(timelist[3])+1)//2+1)%12) and (((int(timelist[3])+1)//2+1)%12) or 12 upperhexagram=((lunar_year+lunar_month+lunar_day)%8) and ((lunar_year+lunar_month+lunar_day)%8) or 8 lowerhexagram=((lunar_year+lunar_month+lunar_day+lunar_hour)%8) and ((lunar_year+lunar_month+lunar_day+lunar_hour)%8) or 8 trans=((lunar_year+lunar_month+lunar_day+lunar_hour)%6) and ((lunar_year+lunar_month+lunar_day+lunar_hour)%6) or 6 solid=hexagram[upperhexagram]+hexagram[lowerhexagram] print(solid) for (key,value) in Yao.items(): if solid in key: print(value)