本文整理汇总了Python中pyopenmensa.feed.LazyBuilder类的典型用法代码示例。如果您正苦于以下问题:Python LazyBuilder类的具体用法?Python LazyBuilder怎么用?Python LazyBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LazyBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: metadata
def metadata(self, request):
meta = LazyBuilder(version=self.parser.version)
meta.feeds.append(Feed(
name='today',
hour='8-14',
url='/'.join([request.host, self.parser.name, self.name, 'today.xml']),
priority=0,
source=None,
dayOfMonth='*',
dayOfWeek='*',
minute='0',
retry=None
))
meta.feeds.append(Feed(
name='full',
hour='8',
url='/'.join([request.host, self.parser.name, self.name, 'full.xml']),
priority=0,
source=None,
dayOfMonth='*',
dayOfWeek='*',
minute='0',
retry=None
))
return meta.toXMLFeed()
示例2: parse_url
def parse_url(url, today=False, canteentype="Mittagsmensa", this_week="", next_week=True, legend_url=None):
canteen = LazyBuilder()
canteen.legendKeyFunc = lambda v: v.lower()
if not legend_url:
legend_url = url[: url.find("essen/") + 6] + "wissenswertes/lebensmittelkennzeichnung"
legend_doc = parse(urlopen(legend_url)).find(id="artikel")
allergene = buildLegend(
text=legend_doc.text.replace("\xa0", " "), regex=r"(?P<name>[A-Z]+) {3,}enthält (?P<value>\w+( |\t|\w)*)"
)
allergene["EI"] = "Ei"
zusatzstoffe = buildLegend(
text=legend_doc.text.replace("\xa0", " "), regex=r"(?P<name>\d+) {3,} (enthält )?(?P<value>\w+( |\t|\w)*)"
)
for tr in legend_doc.find_all("tr"):
tds = tr.find_all("td")
if len(tds) != 2:
continue
title = tds[0].find("strong")
if title is None:
continue
else:
title = title.text
text = tds[1].text.replace("enthält", "").strip()
if title.isdigit():
zusatzstoffe[title] = text
else:
allergene[title] = text
parse_week(url + this_week, canteen, canteentype, allergene=allergene, zusatzstoffe=zusatzstoffe)
if not today and next_week is True:
parse_week(url + "-kommende-woche", canteen, canteentype, allergene=allergene, zusatzstoffe=zusatzstoffe)
if not today and type(next_week) is str:
parse_week(url + next_week, canteen, canteentype, allergene=allergene, zusatzstoffe=zusatzstoffe)
print(canteen.toXMLFeed())
return canteen.toXMLFeed()
示例3: feed_all
def feed_all(self, name):
canteen = LazyBuilder()
date = self.__now()
# Get this week
lastWeekday = -1
while self.handler(canteen, self.xml2locId[name], date.date()):
date += datetime.timedelta(days=1)
if lastWeekday > date.weekday():
break
lastWeekday = date.weekday()
# Skip over weekend
if date.weekday() > 4:
date += datetime.timedelta(days=7-date.weekday())
# Get next week
lastWeekday = -1
while self.handler(canteen, self.xml2locId[name], date.date()):
date += datetime.timedelta(days=1)
if lastWeekday > date.weekday():
break
lastWeekday = date.weekday()
return canteen.toXMLFeed()
示例4: parse_url
def parse_url(url, today=False):
canteen = LazyBuilder()
parse_week(url + '.html', canteen)
if not today:
parse_week(url + '-w1.html', canteen)
parse_week(url + '-w2.html', canteen)
return canteen.toXMLFeed()
示例5: parse_url
def parse_url(url, mensa, *weeks, today):
canteen = LazyBuilder()
for week in weeks:
parse_week(url + week, canteen, mensa)
if today:
break
return canteen.toXMLFeed()
示例6: parse_url
def parse_url(url, today=False):
canteen = LazyBuilder()
parse_week(url + (datetime.date.today()
+ datetime.date.resolution * 7).strftime('/%Y/%W/'), canteen)
if not today:
parse_week(url + (datetime.date.today()
+ datetime.date.resolution * 14).strftime('/%Y/%W/'), canteen)
return canteen.toXMLFeed()
示例7: feed
def feed(self, name):
canteen = LazyBuilder()
if name in self.xmlnames:
parse_url(canteen, name) # all categories
else :
xmlname_enty = [x for x in self.xmlnames if x[0] == name][0]
parse_url(canteen, *xmlname_enty) # only certain categories
return canteen.toXMLFeed()
示例8: parse_url
def parse_url(url, today=False):
canteen = LazyBuilder()
day = datetime.date.today()
for _ in range(21):
parse_day(canteen, '{}&date={}'.format(url, day.strftime('%Y-%m-%d')))
if today:
break
day += datetime.timedelta(days=1)
return canteen.toXMLFeed()
示例9: parse_url
def parse_url(url, today):
canteen = LazyBuilder()
canteen.setAdditionalCharges('student', {})
if today:
parse_week(url, canteen) # base url only contains current day
else:
parse_week(url + 'week', canteen)
parse_week(url + 'nextweek', canteen)
return canteen.toXMLFeed()
示例10: parse_url
def parse_url(url, today=False):
base_data = load_base_data()
canteen = LazyBuilder()
with urlopen(url) as response:
data = json.loads(response.read().decode())
for day in data['days']:
date = datetime.datetime.strptime(day['date'], UTC_DATE_STRING).date()
if today and (datetime.date.today() != date):
continue
for counter in day['counters']:
counter_name = counter['displayName']
counter_description = counter['description']
counter_hours = counter.get('openingHours')
for meal in counter['meals']:
if 'knownMealId' in meal:
# This is meant to allow recognizing recurring meals,
# for features like marking meals as favorites.
# Up to now, not really used in the mensaar.de API,
# nor functional in this API parser.
# The meal will still be recognized as every other meal.
print('knownMealId: %s' % meal['knownMealId'], file=sys.stderr)
meal_name = meal['name']
if 'category' in meal:
meal_name = '%s: %s' % (meal['category'], meal_name)
meal_notes = (
# The description is typically the location
# (but not required to be by the API specification).
build_location(counter_description) +
build_hours(counter_hours) +
build_notes(base_data, meal['notices'], meal['components']))
meal_prices = {}
if 'prices' in meal:
prices = meal['prices']
for role in prices:
if role in ROLES:
meal_prices[base_data['roles'][role]] = prices[role]
if 'pricingNotice' in meal:
meal_notes.append(meal['pricingNotice'])
canteen.addMeal(date, counter_name,
meal_name, meal_notes, meal_prices)
return canteen.toXMLFeed()
示例11: parse_url
def parse_url(url, today=False):
canteen = LazyBuilder()
day = datetime.date.today()
emptyCount = 0
while emptyCount < 7:
if not parse_day(canteen, '{}&day={}&month={}&year={}&limit=25'
.format(url, day.day, day.month, day.year),
day.strftime('%Y-%m-%d')):
emptyCount += 1
else:
emptyCount = 0
if today:
break
day += datetime.date.resolution
return canteen.toXMLFeed()
示例12: parse_url
def parse_url(url, today=False, canteentype='Mittagsmensa', this_week='', next_week=True, legend_url=None):
canteen = LazyBuilder()
canteen.legendKeyFunc = lambda v: v.lower()
if not legend_url:
legend_url = url[:url.find('essen/') + 6] + 'lebensmittelkennzeichnung'
legend_doc = parse(urlopen(legend_url))
canteen.setLegendData(
text=legend_doc.find(id='artikel').text,
regex=r'(?P<name>(\d+|[A-Z]+))\s+=\s+(?P<value>\w+( |\t|\w)*)'
)
parse_week(url + this_week, canteen, canteentype)
if not today and next_week is True:
parse_week(url + '-kommende-woche', canteen, canteentype)
if not today and type(next_week) is str:
parse_week(url + next_week, canteen, canteentype)
return canteen.toXMLFeed()
示例13: parse_url
def parse_url(url, today=False, canteentype='Mittagsmensa', this_week='', next_week=True, legend_url=None):
canteen = LazyBuilder()
canteen.legendKeyFunc = lambda v: v.lower()
if not legend_url:
legend_url = url[:url.find('essen/') + 6] + 'wissenswertes/lebensmittelkennzeichnung'
legend_doc = parse(urlopen(legend_url), 'lxml').find(id='artikel')
allergene = buildLegend(
text=legend_doc.text.replace('\xa0', ' '),
regex=r'(?P<name>[A-Z]+) {3,}enthält (?P<value>\w+( |\t|\w)*)'
)
allergene['EI'] = 'Ei'
zusatzstoffe = buildLegend(
text=legend_doc.text.replace('\xa0', ' '),
regex=r'(?P<name>\d+) {3,} (enthält )?(?P<value>\w+( |\t|\w)*)'
)
suballergene = re.compile(r'(?P<name>[0-9A-Z]+)[^a-zA-Z]*enthält (?P<value>\w+( |\t|\w)*)')
for tr in legend_doc.find_all('tr'):
tds = tr.find_all('td')
if len(tds) != 2:
continue
title = tds[0].find('strong')
if title is None:
continue
else:
title = title.text
lines = tds[1].text.split('\n')
for line in lines[1:]:
try_allergine = suballergene.match(line)
if try_allergine:
allergene[try_allergine.group('name')] = try_allergine.group('value')
text = lines[0].replace('enthält', '').strip()
if title.isdigit():
zusatzstoffe[title] = text
else:
allergene[title] = text
parse_week(url + this_week, canteen, canteentype,
allergene=allergene, zusatzstoffe=zusatzstoffe)
if not today and next_week is True:
parse_week(url + '-kommende-woche', canteen, canteentype,
allergene=allergene, zusatzstoffe=zusatzstoffe)
if not today and type(next_week) is str:
parse_week(url + next_week, canteen, canteentype,
allergene=allergene, zusatzstoffe=zusatzstoffe)
return canteen.toXMLFeed()
示例14: parse_url
def parse_url(url, today=False):
global legend
canteen = LazyBuilder()
canteen.setLegendData(legend)
day = datetime.date.today()
emptyCount = 0
totalCount = 0
while emptyCount < 7 and totalCount < 32:
if not parse_day(canteen, '{}&tag={}&monat={}&jahr={}'
.format(url, day.day, day.month, day.year),
day.strftime('%Y-%m-%d')):
emptyCount += 1
else:
emptyCount = 0
if today:
break
totalCount += 1
day += datetime.date.resolution
return canteen.toXMLFeed()
示例15: parse_url
def parse_url(url, data_canteen, today=False):
canteen = LazyBuilder()
data = urlopen(url).read().decode('utf-8')
document = parse(data, 'lxml')
dish = document.find(class_='neo-menu-single-dishes')
if dish is not None:
dishes = dish.find_all(name='tr', attrs={"data-canteen": data_canteen})
else:
dishes = []
side = document.find(class_='neo-menu-single-modals')
if side is not None:
dishes = dishes + side.find_all(name='tr', attrs={"data-canteen": data_canteen})
for dish in dishes:
parse_dish(dish, canteen)
return canteen.toXMLFeed()