本文整理汇总了Python中utils.Parser.define方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.define方法的具体用法?Python Parser.define怎么用?Python Parser.define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Parser
的用法示例。
在下文中一共展示了Parser.define方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
base_data = {}
base_data['roles'] = {}
base_data['notices'] = data['notices']
for loc in data['locations']:
if loc not in LOCATIONS:
# Found an unknown location
# Please consider updating the parser!
sys.stderr.write(
'Unknown location: %s (displayName: %s)\n' %
(loc, data['locations'][loc]['displayName']))
for role in data['priceTiers']:
if role not in ROLES:
# Found an unknown price tier
# Please consider updating the parser!
sys.stderr.write(
'Unknown price tier: %s (displayName: %s)\n' %
(role, data['priceTiers'][role]))
else:
base_data['roles'][role] = ROLES[role]
return base_data
parser = Parser('saarland',
handler=parse_url,
shared_prefix=URL_BASE + URL_MENU)
for loc in LOCATIONS:
parser.define(loc, suffix=loc)
示例2: Parser
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
allergene=allergene, zusatzstoffe=zusatzstoffe)
return canteen.toXMLFeed()
parser = Parser('ostniedersachsen', handler=parse_url,
shared_prefix='http://www.stw-on.de')
sub = parser.sub('braunschweig',
shared_prefix='/braunschweig/essen/menus/')
sub.define('mensa1-mittag', suffix='mensa-1', extra_args={'canteentype': 'Mittagsmensa'})
sub.define('mensa1-abend', suffix='mensa-1', extra_args={'canteentype': 'Abendmensa'})
sub.define('mensa360', suffix='360', extra_args={'canteentype': 'Pizza', 'this_week': '-2', 'next_week': '-nachste-woche'})
sub.define('mensa2', suffix='mensa-2')
sub.define('hbk', suffix='mensa-hbk')
parser.define('clausthal', suffix='/clausthal/essen/menus/mensa-clausthal',
extra_args={'next_week': '-kommend-woche'})
sub = parser.sub('hildesheim', shared_prefix='/hildesheim/essen/menus/')
sub.define('uni', suffix='mensa-uni')
sub.define('hohnsen', suffix='mensa-hohnsen')
sub.define('luebecker-strasse', suffix='luebecker-strasse', extra_args={'canteentype': 'Mittagsausgabe'})
parser.sub('suderburg').define('campus', suffix='/suderburg/essen/menus/mensa-suderburg')
parser.sub('wolfenbuettel').define('ostfalia', suffix='/wolfenbuettel/essen/menus/mensa-ostfalia')
parser.sub('holzminden', shared_prefix='/holzminden/essen/menus/') \
.define('hawk', suffix='mensa-hawk', extra_args={'next_week': False})
sub = parser.sub('lueneburg', shared_prefix='/lueneburg/essen/speiseplaene/')
sub.define('campus', suffix='mensa-campus')
sub.define('rotes-feld', suffix='rotes-feld')
示例3: type
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
while type(mensa_data) != Tag or mensa_data.name != 'div'\
or 'tx-cagcafeteria-pi1' not in mensa_data.get('class', []):
mensa_data = mensa_data.next_sibling
weekDays = extractWeekDates(mensa_data.find('h2').text)
for day_headline in mensa_data.find_all('h3'):
date = weekDays[day_headline.text]
day_table = day_headline.next_sibling.next_sibling
for tr_menu in day_table.tbody.find_all('tr'):
category = tr_menu.find_all('td')[0].text.strip()
name = tr_menu.find_all('td')[1].text.replace('\r\n', ' ').strip()
canteen.addMeal(date, category, name, [], tr_menu.find_all('td')[2].text)
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()
parser = Parser('marburg', handler=parse_url,
shared_args=['http://www.studentenwerk-marburg.de/essen-trinken/speiseplan/'])
parser.define('bistro', args=['Speiseplan.*Bistro', 'diese-woche-bistro.html', 'naechste-woche-bistro.html'])
parser.define('mos-diner', args=['Speiseplan.*Diner', 'diese-woche-mos-diner.html'])
parser.define('erlenring', args=['Mensa Erlenring', 'diese-woche-mensa-erlenring-und-lahnberge.html',
'naechste-woche-mensa-erlenring-und-lahnberge.html'])
parser.define('lahnberge', args=['Mensa Lahnberge', 'diese-woche-mensa-erlenring-und-lahnberge.html',
'naechste-woche-mensa-erlenring-und-lahnberge.html'])
示例4: parse_url
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
canteen.addMeal(date, category, name, notes,
prices, roles)
def parse_url(url, today=False):
canteen = LazyBuilder()
parse_week(url + '.html?view=list', canteen)
if not today:
parse_week(url + '-w1.html?view=list', canteen)
parse_week(url + '-w2.html?view=list', canteen)
return canteen.toXMLFeed()
parser = Parser('dresden', handler=parse_url,
shared_prefix='https://www.studentenwerk-dresden.de/mensen/speiseplan/')
parser.define('reichenbachstrasse', suffix='mensa-reichenbachstrasse')
parser.define('zeltschloesschen', suffix='zeltschloesschen')
parser.define('alte-mensa', suffix='alte-mensa')
parser.define('mensologie', suffix='mensologie')
parser.define('siedepunkt', suffix='mensa-siedepunkt')
parser.define('johannstadt', suffix='mensa-johannstadt')
parser.define('wueins', suffix='mensa-wueins')
parser.define('bruehl', suffix='mensa-bruehl')
parser.define('u-boot', suffix='u-boot')
parser.define('tellerrandt', suffix='mensa-tellerrandt')
parser.define('zittau', suffix='mensa-zittau')
parser.define('stimm-gabel', suffix='mensa-stimm-gabel')
parser.define('palucca-schule', suffix='mensa-palucca-schule')
parser.define('goerlitz', suffix='mensa-goerlitz')
parser.define('sport', suffix='mensa-sport')
parser.define('kreuzgymnasium', suffix='mensa-kreuzgymnasium')
示例5: print
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
# multiple prices for a meal - keep all of them literally
name = mealCellText
price = None
try:
date=dates[dateIdx]
canteen.addMeal(date, category=subCanteen, name=name, prices=price)
except ValueError as e:
print('Error adding meal {} on {}: {}'.format(name, date, e))
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()
parser = Parser('darmstadt', handler=parse_url,
shared_prefix='https://www.stwda.de/components/com_spk/')
parser.define('stadtmitte', suffix='spk_Stadtmitte_print.php?ansicht=')
parser.define('lichtwiese', suffix='spk_Lichtwiese_print.php?ansicht=')
parser.define('schoefferstrasse', suffix='spk_Schoefferstrasse_print.php?ansicht=')
parser.define('dieburg', suffix='spk_Dieburg_print.php?ansicht=')
parser.define('haardtring', suffix='spk_Haardtring_print.php?ansicht=')
示例6: parse_foot_type
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
food_type = parse_foot_type(tds[2])
food_description = get_foot_description(tds[3])
notes_string = build_notes_string(tds[3])
if(notes_string != ""):
notes.append(notes_string)
prices = get_pricing(tds, 4, 7)
if food_type is not None:
canteen.addMeal(date, food_type, food_description, notes, prices, roles if prices else None)
except Exception as e:
traceback.print_exception(*sys.exc_info())
return canteen.toXMLFeed()
parser = Parser('erlangen_nuernberg',
handler=parse_url,
shared_prefix='http://www.studentenwerk.uni-erlangen.de/verpflegung/de/')
parser.define('er-langemarck', suffix='sp-er-langemarck.shtml')
parser.define('er-sued', suffix='sp-er-sued.shtml')
parser.define('n-schuett', suffix='sp-n-schuett.shtml')
parser.define('n-regens', suffix='sp-n-regens.shtml')
parser.define('n-stpaul', suffix='sp-n-stpaul.shtml')
parser.define('n-mensateria', suffix='sp-n-mensateria.shtml')
parser.define('n-hohfederstr', suffix='sp-n-hohfederstr.shtml')
parser.define('n-baerenschanzstr', suffix='sp-n-baerenschanzstr.shtml')
parser.define('eichstaett', suffix='sp-eichstaett.shtml')
parser.define('ingolstadt', suffix='sp-ingolstadt.shtml')
parser.define('ansbach', suffix='sp-ansbach.shtml')
parser.define('triesdorf', suffix='sp-triesdorf.shtml')
示例7: parse_day
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
day = datetime.date.today()
emptyCount = 0
totalCount = 0
while emptyCount < 7 and totalCount < 32:
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
totalCount += 1
day += datetime.date.resolution
return canteen.toXMLFeed()
parser = Parser('leipzig', handler=parse_url,
shared_prefix='http://www.studentenwerk-leipzig.de/mensen-und-cafeterien/speiseplan/m/meals.php?canteen=')
parser.define('dittrichring', suffix='153')
parser.define('koburger-strasse', suffix='121')
parser.define('philipp-rosenthal-strasse', suffix='127')
parser.define('waechterstrasse', suffix='129')
parser.define('academica', suffix='118')
parser.define('am-park', suffix='106')
parser.define('am-elsterbecken', suffix='115')
parser.define('liebigstrasse', suffix='162')
parser.define('peterssteinweg', suffix='111')
parser.define('schoenauer-strasse', suffix='140')
parser.define('tierklinik', suffix='170')
示例8: parse_url
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
elif group == 'Bed.:':
prices['employee'] = price
elif group == 'Gast:':
prices['other'] = price
canteen.addMeal(date, category, menuName, notes, prices)
else:
canteen.setDayClosed(date)
# check for further pages
nextPageLink = dom.find(id='next_day_link')
if nextPageLink == None or today:
url = None
else:
url = 'https://www.studentenwerk-rostock.de/' + nextPageLink['href']
return canteen.toXMLFeed()
def parse_url(url, today=False):
splitted = url.split('#')
return parsePlan(splitted[0], splitted[1], today)
parser = Parser('rostock', handler=parse_url, shared_prefix='https://www.studentenwerk-rostock.de/de/mensen/speiseplaene.html')
parser.define('mensa-sued', suffix='#mensa_id_1')
parser.define('campus-cafeteria-einstein', suffix='#mensa_id_13')
parser.define('mensa-st-georg-straße', suffix='#mensa_id_2')
parser.define('mensa-multiple-choice', suffix='#mensa_id_14')
parser.define('mensa-kleine-ulme', suffix='#mensa_id_3')
parser.define('mensa-ulme-69', suffix='#mensa_id_8')
parser.define('campus-mensa-wismar', suffix='#mensa_id_5')
示例9: parse_week
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
from bs4 import BeautifulSoup
from pyopenmensa.feed import LazyBuilder
from urllib.request import urlopen
from utils import Parser
def parse_week(url, canteen):
soup = BeautifulSoup(urlopen(url).read(), 'lxml')
plan_table = soup.find("table", "tabmensaplan")
for day_span in plan_table.find_all("span", "tabDate"):
meal_date = day_span.text + "2015"
for index, meal_td in enumerate(day_span.parent.parent.find_all("td")):
if index > 0 and index < 5:
meal_text = meal_td.text
meal_type = soup.find_all("span", "mvmensa")[index-1].text
canteen.addMeal(meal_date, meal_type, meal_text)
def parse_url(url, today):
canteen = LazyBuilder()
if not today:
parse_week(url, canteen)
return canteen.toXMLFeed()
parser = Parser('siegen', handler=parse_url,
shared_prefix='http://studentenwerk.uni-siegen.de/index.php?uid=650&uid2=0')
parser.define('ar', suffix='&cat_show=1')
parser.define('enc', suffix='&cat_show=2')
parser.define('ars-mundi', suffix='&cat_show=3')
parser.define('cafeterien', suffix='&cat_show=4')
示例10: parse_url
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
prices, ('student', 'employee', 'other')
)
i += 1
def parse_url(url, today=False):
canteen = LazyBuilder()
parse_week(url, date.today(), canteen)
if not today:
parse_week(url, date.today() + date.resolution * 7, canteen)
return canteen.toXMLFeed()
parser = Parser('hamburg', handler=parse_url,
shared_prefix='http://speiseplan.studierendenwerk-hamburg.de/de/')
parser.define('armgartstrasse', suffix='590')
parser.define('bergedorf', suffix='520')
parser.define('berliner-tor', suffix='530')
parser.define('botanischer-garten', suffix='560')
parser.define('bucerius-law-school', suffix='410')
parser.define('cafe-mittelweg', suffix='690')
parser.define('cafe-cfel', suffix='680')
parser.define('cafe-jungiusstrasse', suffix='610')
parser.define('cafe-alexanderstrasse', suffix='660')
parser.define('campus', suffix='340')
parser.define('finkenau', suffix='420')
parser.define('geomatikum', suffix='540')
parser.define('harburg', suffix='570')
parser.define('hcu', suffix='430')
parser.define('philosophenturm', suffix='350')
parser.define('stellingen', suffix='580')
示例11: print
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
if notematch not in legends:
print('unknown legend: {}'.format(notematch))
continue
notes.append(legends[notematch])
canteen.addMeal(date, category, name, notes,
price_regex.findall(line), roles)
def parse_url(url, today=False):
canteen = LazyBuilder()
parse_week(url + '&wann=2', canteen)
if not today:
parse_week(url + '&wann=3', canteen)
return canteen.toXMLFeed()
parser = Parser('hannover', handler=parse_url,
shared_prefix='http://www.stwh-portal.de/mensa/index.php?format=txt&wo=')
parser.define('hauptmensa', suffix='2')
parser.define('hauptmensa-marktstand', suffix='9')
parser.define('restaurant-ct', suffix='10')
parser.define('contine', suffix='3')
parser.define('pzh', suffix='13')
parser.define('caballus', suffix='1')
parser.define('tiho-tower', suffix='0')
parser.define('hmtmh', suffix='8')
parser.define('ricklinger-stadtweg', suffix='6')
parser.define('kurt-schwitters-forum', suffix='7')
parser.define('blumhardtstrasse', suffix='14')
parser.define('herrenhausen', suffix='12')
示例12: print
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
price_tag = meal_item.find("span", {"class": "fmc-item-price"})
try:
canteen.addMeal(date, category=location_tag.string, name=title_tag.string, prices=price_tag.string)
except ValueError as e:
print('Error adding meal "{}": {}'.format(meal_item, e))
def parse_url(url, today=False):
canteen = LazyBuilder()
canteen.setAdditionalCharges("student", {})
parse_week(url, canteen)
return canteen.toXMLFeed()
parser = Parser(
"darmstadt",
handler=parse_url,
shared_prefix="http://studierendenwerkdarmstadt.de/hochschulgastronomie/speisekarten/",
)
parser.define("stadtmitte", suffix="stadtmitte/")
parser.define("lichtwiese", suffix="lichtwiese/")
parser.define("schoefferstrasse", suffix="schoefferstrasse/")
parser.define("dieburg", suffix="dieburg/")
parser.define("haardtring", suffix="haardtring/")
# for debugging / testing
if __name__ == "__main__":
print(parser.parse("darmstadt", "stadtmitte", None))
示例13: parse_url
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
for img in meal_tr.contents[1].find_all("img"):
notes.append(img["title"])
canteen.addMeal(date, category, name, notes, price_regex.findall(meal_tr.contents[2].text), roles)
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()
parser = Parser("dresden", handler=parse_url, shared_prefix="http://www.studentenwerk-dresden.de/mensen/speiseplan/")
parser.define("reichenbachstrasse", suffix="mensa-reichenbachstrasse")
parser.define("zeltschloesschen", suffix="zeltschloesschen")
parser.define("alte-mensa", suffix="alte-mensa")
parser.define("mensologie", suffix="mensologie")
parser.define("siedepunkt", suffix="mensa-siedepunkt")
parser.define("johannstadt", suffix="mensa-johannstadt")
parser.define("wueins", suffix="mensa-wueins")
parser.define("bruehl", suffix="mensa-bruehl")
parser.define("u-boot", suffix="u-boot")
parser.define("tellerrandt", suffix="mensa-tellerrandt")
parser.define("zittau", suffix="mensa-zittau")
parser.define("stimm-gabel", suffix="mensa-stimm-gabel")
parser.define("palucca-schule", suffix="mensa-palucca-schule")
parser.define("goerlitz", suffix="mensa-goerlitz")
parser.define("sport", suffix="mensa-sport")
parser.define("kreuzgymnasium", suffix="mensa-kreuzgymnasium")
示例14: Parser
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
price_div = meal_article.find('div', 'price')
if price_div:
for k, v in price_map.items():
price = price_div['data-' + k]
if price:
prices[v] = price
canteen.addMeal(date, category, name, notes, prices)
if closed_candidate and not canteen.hasMealsFor(date):
canteen.setDayClosed(date)
return canteen.toXMLFeed()
parser = Parser('wuerzburg', handler=parse_url,
shared_prefix='https://www.studentenwerk-wuerzburg.de/essen-trinken/speiseplaene/plan/')
parser.define('austrasse', suffix='austrasse-bamberg.html')
parser.define('burse', suffix='burse-am-studentenhaus-wuerzburg.html')
parser.define('feldkirchenstrasse', suffix='feldkirchenstrasse-bamberg.html')
#parser.define('frankenstube', suffix='frankenstube-wuerzburg.html')
#parser.define('hubland', suffix='mensa-am-hubland-wuerzburg.html')
parser.define('studentenhaus', suffix='mensa-am-studentenhaus.html')
parser.define('aschaffenburg', suffix='mensa-aschaffenburg.html')
parser.define('augenklinik', suffix='mensa-roentgenring-wuerzburg.html')
parser.define('josef-schneider', suffix='mensa-josef-schneider-strasse-wuerzburg.html')
parser.define('schweinfurt', suffix='mensa-schweinfurt.html')
parser.define('mensateria', suffix='mensateria-campus-hubland-nord-wuerzburg.html')
parser.define('philo', suffix='philosophie-wuerzburg.html')
parser.define('sprachenzentrum', suffix='interimsmensa-im-sprachenzentrum-ab-9-april-2018.html')
示例15: parse_url
# 需要导入模块: from utils import Parser [as 别名]
# 或者: from utils.Parser import define [as 别名]
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()
parser = Parser('marburg', handler=parse_url,
shared_args=['https://studentenwerk-marburg.de/essen-trinken/speisekarte/'])
parser.define('bistro', args=[460])
parser.define('mos-diner', args=[420])
parser.define('erlenring', args=[330])
parser.define('lahnberge', args=[340])
parser.define('cafeteria-lahnberge', args=[490])