当前位置: 首页>>代码示例>>Python>>正文


Python utils.Parser类代码示例

本文整理汇总了Python中utils.Parser的典型用法代码示例。如果您正苦于以下问题:Python Parser类的具体用法?Python Parser怎么用?Python Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: thisWeek

        return self.feed.toXMLFeed()

    @Source.feed(name="thisWeek", priority=1, hour="8", retry="2 60")
    def thisWeek(self, request):
        day = datetime.datetime.now().isocalendar()
        self.parse_data(week=day[1], year=day[0])
        return self.feed.toXMLFeed()

    @Source.feed(name="nextWeek", priority=2, hour="9")
    def nextWeek(self, request):
        day = (datetime.datetime.now() + 7 * datetime.date.resolution).isocalendar()
        self.parse_data(week=day[1], year=day[0])
        return self.feed.toXMLFeed()


parser = Parser(name="halle", version=1.0)
Canteen("harzmensa", parser, location=3, needed_title="Harzmensa")
Canteen("weinbergmensa", parser, location=5, needed_title="Weinbergmensa")
# Canteen('cafebar-weinberg', parser, location=, needed_title='')
Canteen("tulpe", parser, location=10, needed_title="Mensa Tulpe")
Canteen("heidemensa", parser, location=17, needed_title="Heidemensa")
Canteen("burg", parser, location=12, needed_title="Mensa Burg")
Canteen("neuwerk", parser, location=9, needed_title="Neuwerk")
Canteen("franckesche-stiftungen", parser, location=14, needed_title="Franckesche Stiftungen")

# merseburg = parser.sub('merseburg')
Canteen("merseburg", parser, location=16, needed_title="Mensa Merseburg", not_halle=True)
# Canteen('cafebar-merseburg', merseburg, location=, needed_title=)

# dessau = parser.sub('dessau')
Canteen("dessau", parser, location=13, needed_title="Mensa Dessau", not_halle=True)
开发者ID:shad0w73,项目名称:openmensa-parsers,代码行数:31,代码来源:halle.py

示例2: parse_week

        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()


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')
开发者ID:azrdev,项目名称:openmensa-parsers,代码行数:32,代码来源:ostniedersachsen.py

示例3: type

    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'])
开发者ID:azrdev,项目名称:openmensa-parsers,代码行数:30,代码来源:marburg.py

示例4: parse_url

                    prices = []

                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')
开发者ID:mswart,项目名称:openmensa-parsers,代码行数:32,代码来源:dresden.py

示例5: print

                # 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=')
开发者ID:RafiKueng,项目名称:openmensa-parsers,代码行数:30,代码来源:darmstadt.py

示例6: parse_foot_type

                        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')
开发者ID:m8mble,项目名称:openmensa-parsers,代码行数:30,代码来源:erlangen_nuernberg.py

示例7: parse_day

    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')
开发者ID:RafiKueng,项目名称:openmensa-parsers,代码行数:30,代码来源:leipzig.py

示例8: parse_week

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')
开发者ID:a-andre,项目名称:openmensa-parsers,代码行数:28,代码来源:siegen.py

示例9: 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()


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])
开发者ID:mswart,项目名称:openmensa-parsers,代码行数:29,代码来源:marburg.py

示例10: print

            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')
开发者ID:azrdev,项目名称:openmensa-parsers,代码行数:30,代码来源:hannover.py

示例11: parse_url

                            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')
开发者ID:azrdev,项目名称:openmensa-parsers,代码行数:30,代码来源:rostock.py

示例12: list

                canteen.addMeal(weekDays[i], category, name,
                                list(set(notes)),
                                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')
开发者ID:a-andre,项目名称:openmensa-parsers,代码行数:32,代码来源:hamburg.py

示例13: print

            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))
开发者ID:shad0w73,项目名称:openmensa-parsers,代码行数:30,代码来源:darmstadt.py

示例14: parse_url

            notes = []
            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")
开发者ID:mswart,项目名称:openmensa-parsers,代码行数:31,代码来源:dresden.py

示例15: in

            price_div = meal_article.find('div', 'price')
            if price_div is None:
                canteen.addMeal(date, category, name, notes)
                continue
            prices = {}
            for v, r in (('default', 'student'), ('bed', 'employee'), ('guest', 'other')):
                price = price_regex.search(price_div['data-' + v])
                if price:
                    prices[r] = price.group('price')
                elif v == 'default':
                    prices = {}
                    break
            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='http://www.studentenwerk-wuerzburg.de/essen-trinken/speiseplaene/plan/show/')
parser.define('austrasse', suffix='austrasse-bamberg.html')
parser.define('burse', suffix='burse-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')
parser.define('augenklinik', suffix='mensa-augenklinik-wuerzburg.html')
parser.define('josef-schneider', suffix='mensa-josef-schneider-strasse-wuerzburg.html')
parser.define('schweinfurt', suffix='mensa-schweinfurt.html')
开发者ID:azrdev,项目名称:openmensa-parsers,代码行数:30,代码来源:wuerzburg.py


注:本文中的utils.Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。