python 为洛杉矶健身俱乐部生成一个ics(icalendar / ical)。你必须知道俱乐部的身份证,你可以通过他们的网站获得

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 为洛杉矶健身俱乐部生成一个ics(icalendar / ical)。你必须知道俱乐部的身份证,你可以通过他们的网站获得相关的知识,希望对你有一定的参考价值。

from pyquery import PyQuery as pq
from icalendar import Calendar, Event
import datetime
from datetime import date, timedelta
from dateutil.relativedelta import *
from dateutil.parser import *
from pprint import pprint as pp

clubid = 722
url = "https://www.lafitness.com/Pages/ClassSchedulePrintVersion.aspx?clubid=%s" % clubid
d = pq(url=url)
elements = d("#tblSchedule > tr > td")

# Calculate some important variables.
now = datetime.datetime.now()
hours = [x.text.replace('\t','').replace('\r\n','') for x in elements.find('h5')]
location = d("td[valign=middle]").text().replace('\t','').replace('\r\n',' ')


classes = []
for ele in elements:
	cur = []
	for e in ele.findall("b"):
		print e.getchildren()[0].text.encode('ascii','ignore')
		try:
			print cur
			cur.extend([e.getchildren()[0].text.encode('ascii','ignore')])
		except:
			pass
	classes.append(cur)

print pp(classes)

# Restructure Classes
rclass = []
for x in range(0,len(classes),8):
	rclass.append(classes[x+1:x+8])


cal = Calendar()
cal.add('prodid', '-//LA Fitness//mxm.dk//')
cal.add('version', '2.0')
cal.add('dtstart', now-timedelta(days=7))

i = 0
for time in enumerate(hours):
	for f,dayset in enumerate(rclass[time[0]]):
		if dayset != []:
			for day in dayset:
				i += 1
				event = Event()
				event.add('summary',day)
				event['uid'] = "lafitness" + str(clubid) + "_" + str(i)
				t = parse(time[1])
				event.add('dtstart', datetime.datetime.combine(date.today(),t.time())+relativedelta(weekday=f-1))
				event.add('dtend', datetime.datetime.combine(date.today(),t.time())+relativedelta(weekday=f-1,hours=1))
				event.add('RRULE:FREQ=WEEKLY','',parameters={'COUNT': '100'})
				event.add('URL',url)
				event.add('LOCATION',location.title())
				cal.add_component(event)



cal['summary'] = 'LA Fitness iCal'

f = open('LA Fitness %s.ics' % clubid,'wr')
f.write(cal.to_ical())

以上是关于python 为洛杉矶健身俱乐部生成一个ics(icalendar / ical)。你必须知道俱乐部的身份证,你可以通过他们的网站获得的主要内容,如果未能解决你的问题,请参考以下文章

基于ssm健身俱乐部网站

多个地方的Drupal 7事件 - 多对多的关系

想做一个完美的健身训练计划,你须要知道什么?

女生适合做健身教练吗?

从Google地图获取数据

手把手搭建Java健身房管理系统附源码(毕设)