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


Python Interpreter.get_new_event_from_string方法代码示例

本文整理汇总了Python中interpreter.Interpreter.get_new_event_from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.get_new_event_from_string方法的具体用法?Python Interpreter.get_new_event_from_string怎么用?Python Interpreter.get_new_event_from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在interpreter.Interpreter的用法示例。


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

示例1: download_planning

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import get_new_event_from_string [as 别名]
def download_planning(uuid):
    planning = _get_planning(uuid)
    if not planning:
        return jsonify({"message": 'Planning with uuid "%s" not found' % uuid}), 404

    moodle_archive_path = planning.mbz_fullpath
    planning_txt = planning.planning_txt

    if not planning_txt:
        return _bad_request()

    # Make tmp directory for MBZ extraction and ics download
    with tempfile.TemporaryDirectory() as tmp_path:
        # Download calendar to tmp folder
        calendar_path = _dl_and_save_ics_file(planning.ics_url, tmp_path)
        calendar = CalendarReader(calendar_path)
        calendar_meetings = calendar.get_all_meetings()

        # Extract Moodle course to tmp folder
        with tarfile.open(moodle_archive_path) as tar_file:
            tar_file.extractall(tmp_path)
            course = MoodleCourse(tmp_path)

        interpreter = Interpreter(calendar_meetings, course)
        for line in planning_txt.split("\n"):
            event = interpreter.get_new_event_from_string(line)
            course.replace_event(event)
        folder = os.path.join(app.config["UPLOAD_FOLDER"], uuid)
        latest_mbz_path = os.path.join(folder, "latest.mbz")

        course.write(latest_mbz_path)
        return send_from_directory(folder, "latest.mbz", as_attachment=True)
开发者ID:hubuhuan,项目名称:course-activity-planner,代码行数:34,代码来源:course_activity_planner.py

示例2: download_planning

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import get_new_event_from_string [as 别名]
def download_planning(uuid):
    try:
        planning = _get_planning(uuid, g.user_id)
    except CAPException as e:
        return e.res

    moodle_archive_path = planning.mbz_fullpath
    planning_txt = planning.planning_txt

    if not planning_txt:
        return _bad_request()

    # Make tmp directory for MBZ extraction and ics download
    with tempfile.TemporaryDirectory() as tmp_path:
        # Download calendar to tmp folder
        calendar = CalendarReader(planning.ics_fullpath)
        calendar_meetings = calendar.get_all_meetings()

        # Extract Moodle course to tmp folder
        with tarfile.open(moodle_archive_path) as tar_file:
            tar_file.extractall(tmp_path)
            course = MoodleCourse(tmp_path)

        interpreter = Interpreter(calendar_meetings, course)
        for line in planning_txt.split('\n'):
            event = interpreter.get_new_event_from_string(line)
            course.replace_event(event)

        folder = os.path.join(app.config['UPLOAD_FOLDER'], uuid)
        latest_mbz_path = os.path.join(folder, 'latest.mbz')

        course.write(latest_mbz_path)
        return send_from_directory(
            folder, 'latest.mbz', as_attachment=True)
开发者ID:fxleblanc,项目名称:course-activity-planner,代码行数:36,代码来源:course_activity_planner.py

示例3: preview_planning

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import get_new_event_from_string [as 别名]
def preview_planning(uuid):
    planning = _get_planning(uuid)
    if not planning:
        return jsonify({"message": 'Planning with uuid "%s" not found' % uuid}), 404

    moodle_archive_path = planning.mbz_fullpath
    planning_txt = planning.planning_txt

    # Make tmp directory for MBZ extraction and ics download
    with tempfile.TemporaryDirectory() as tmp_path:
        # Download calendar to tmp folder
        calendar_path = _dl_and_save_ics_file(planning.ics_url, tmp_path)
        calendar = CalendarReader(calendar_path)
        calendar_meetings = calendar.get_all_meetings()

        # Extract Moodle course to tmp folder
        with tarfile.open(moodle_archive_path) as tar_file:
            tar_file.extractall(tmp_path)
            course = MoodleCourse(tmp_path)

    interpreter = Interpreter(calendar_meetings, course)

    # Build preview
    preview = []

    if planning_txt:
        for line in planning_txt.split("\n"):
            event = interpreter.get_new_event_from_string(line)
            pretty_event_name = event.get_pretty_name()

            preview.append(
                {"title": "%s %d opens" % (pretty_event_name, event.rel_id), "timestamp": event.get_start_timestamp()}
            )
            preview.append(
                {"title": "%s %d closes" % (pretty_event_name, event.rel_id), "timestamp": event.get_end_timestamp()}
            )

    for meeting_type in calendar_meetings:
        clazz = meeting_type.__name__

        for i, meeting in enumerate(calendar_meetings[meeting_type]):
            rel_id = i + 1
            preview.append({"title": "%s %d opens" % (clazz, rel_id), "timestamp": meeting.get_start_timestamp()})
            preview.append({"title": "%s %d closes" % (clazz, rel_id), "timestamp": meeting.get_end_timestamp()})

    # Return preview sorted by timestamp
    return jsonify({"preview": sorted(preview, key=lambda p: p["timestamp"])}), 200
开发者ID:hubuhuan,项目名称:course-activity-planner,代码行数:49,代码来源:course_activity_planner.py

示例4: InterpreterTestOtherActivities

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import get_new_event_from_string [as 别名]
class InterpreterTestOtherActivities(unittest.TestCase):

    calendar_path = '../data/multi-fr.ics'
    moodle_archive_path = '../data/all-activities.mbz'

    def setUp(self):
        # Setup calendar
        calendar = CalendarReader(self.calendar_path)

        self.calendar_meetings = calendar.get_all_meetings()

        # Setup Moodle course
        self.tmp_path = tempfile.mkdtemp()
        with tarfile.open(self.moodle_archive_path) as tar_file:
            tar_file.extractall(self.tmp_path)

        self.course = MoodleCourse(self.tmp_path)
        self.interpreter = Interpreter(self.calendar_meetings, self.course)

    def tearDown(self):
        # TODO test on windows
        shutil.rmtree(self.tmp_path)

    def test_homework_as_start_and_end(self):
        expected_s = arrow.get(
            2015, 10, 1, 0, tzinfo=tz.gettz('America/Montreal')).datetime
        expected_e = arrow.get(
            2015, 10, 29, 0, tzinfo=tz.gettz('America/Montreal')).datetime
        actual = self.interpreter.get_new_event_from_string('MQ1 mh1 mh1f')
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

    def test_lesson_as_start_and_end(self):
        expected_s = arrow.get(
            2016, 2, 10, 13, tzinfo=tz.gettz('America/Montreal')).datetime
        expected_e = arrow.get(
            2016, 2, 10, 15, tzinfo=tz.gettz('America/Montreal')).datetime
        actual = self.interpreter.get_new_event_from_string('MQ1 ml1 ml1f')
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

    def test_choice_as_start_and_end(self):
        expected_s = arrow.get(
            2016, 2, 10, 13, tzinfo=tz.gettz('America/Montreal')).datetime
        expected_e = arrow.get(
            2016, 2, 10, 14, tzinfo=tz.gettz('America/Montreal')).datetime
        actual = self.interpreter.get_new_event_from_string('MQ1 mc1 mc1f')
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

    def test_feedback_as_start_and_end(self):
        expected_s = arrow.get(
            2016, 2, 10, 13, 0, tzinfo=tz.gettz('America/Montreal')).datetime
        expected_e = arrow.get(
            2016, 2, 10, 13, 5, tzinfo=tz.gettz('America/Montreal')).datetime
        actual = self.interpreter.get_new_event_from_string('MQ1 mf1 mf1f')
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)
开发者ID:jdupl,项目名称:course-activity-planner,代码行数:68,代码来源:interpreter_test.py

示例5: InterpreterTest

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import get_new_event_from_string [as 别名]

#.........这里部分代码省略.........
        expected = arrow.get(2014, 1, 6, 22, 0).datetime
        actual = self.interpreter._get_datetime_from_token('S1+10h')
        self.assertEqual(expected, actual)
        expected = arrow.get(2014, 1, 16, 12, 0).datetime
        actual = self.interpreter._get_datetime_from_token('S1+10D')
        self.assertEqual(expected, actual)

    def test_get_subject(self):
        tokens = self.interpreter._split_line('MQ1 S1 S1F')
        actual = self.interpreter._parse_subject(tokens)['id']
        self.assertEqual('4271', actual)

        tokens = self.interpreter._split_line('MQ2 S1 S1F')
        actual = self.interpreter._parse_subject(tokens)['id']
        self.assertEqual('4272', actual)

        tokens = self.interpreter._split_line('MQ3 S1 S1F')
        actual = self.interpreter._parse_subject(tokens)['id']
        self.assertEqual('4273', actual)

    def test_handle_invalid_subject(self):
        # Seminars can't be used as subject
        tokens = self.interpreter._split_line('S1 Q1 Q1F')
        self.assertRaises(
            InvalidSubjectException,
            self.interpreter._parse_subject, tokens)

        # Practica can't be used as subject
        tokens = self.interpreter._split_line('P1 Q1 Q1F')
        self.assertRaises(
            InvalidSubjectException,
            self.interpreter._parse_subject, tokens)

    def test_get_new_event_from_string(self):
        expected_s = arrow.get(
            2014, 1, 6, 7, tzinfo=tz.gettz('America/Montreal')).datetime
        expected_e = arrow.get(
            2014, 1, 6, 8, tzinfo=tz.gettz('America/Montreal')).datetime
        actual = self.interpreter.get_new_event_from_string('MQ1 S1S S1F')
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(
            2014, 1, 13, 7, tzinfo=tz.gettz('America/Montreal')).datetime
        expected_e = arrow.get(
            2014, 1, 20, 8, tzinfo=tz.gettz('America/Montreal')).datetime
        actual = self.interpreter.get_new_event_from_string('MQ1 S2 S3F')
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(
            2014, 1, 13, 7, tzinfo=tz.gettz('America/Montreal')).datetime
        expected_e = arrow.get(
            2014, 1, 20, 8, tzinfo=tz.gettz('America/Montreal')).datetime
        actual = self.interpreter.get_new_event_from_string('MH1 S2 S3F')
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(
            2014, 1, 8, 8, tzinfo=tz.gettz('America/Montreal')).datetime
开发者ID:jdupl,项目名称:course-activity-planner,代码行数:70,代码来源:interpreter_test.py

示例6: InterpreterTest

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import get_new_event_from_string [as 别名]

#.........这里部分代码省略.........
        actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1).datetime, timedelta(minutes=1), None)
        self.assertEqual(expected, actual)

        expected = arrow.get(2000, 1, 1).datetime
        actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1, 0, 2).datetime, timedelta(minutes=-2), None)
        self.assertEqual(expected, actual)

        expected = arrow.get(2000, 1, 1, 3).datetime
        actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1).datetime, timedelta(hours=3), None)
        self.assertEqual(expected, actual)

        expected = arrow.get(1999, 12, 31).datetime
        actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1).datetime, timedelta(days=-1), None)
        self.assertEqual(expected, actual)

        expected = arrow.get(2000, 1, 1, 2, 5).datetime
        actual = self.interpreter._get_new_datetime(arrow.get(2000, 1, 1).datetime, None, time(hour=2, minute=5))
        self.assertEqual(expected, actual)

        expected = arrow.get(2000, 1, 2, 2, 5).datetime
        actual = self.interpreter._get_new_datetime(
            arrow.get(2000, 1, 1, 0, 0, 0).datetime, timedelta(days=1), time(hour=2, minute=5)
        )
        self.assertEqual(expected, actual)

        expected = arrow.get(1999, 12, 31, 23, 55).datetime
        actual = self.interpreter._get_new_datetime(
            arrow.get(2000, 1, 1).datetime, timedelta(days=-1), time(hour=23, minute=55)
        )
        self.assertEqual(expected, actual)

    def test_get_subject(self):
        tokens = self.interpreter._split_line("Q1 S1 S1F")
        actual = self.interpreter._parse_subject(tokens)["id"]
        self.assertEqual("4271", actual)

        tokens = self.interpreter._split_line("Q2 S1 S1F")
        actual = self.interpreter._parse_subject(tokens)["id"]
        self.assertEqual("4272", actual)

        tokens = self.interpreter._split_line("Q3 S1 S1F")
        actual = self.interpreter._parse_subject(tokens)["id"]
        self.assertEqual("4273", actual)

    def test_get_new_event_from_string(self):
        expected_s = arrow.get(2014, 1, 6, 7, tzinfo=tz.gettz("America/Montreal")).datetime
        expected_e = arrow.get(2014, 1, 6, 8, tzinfo=tz.gettz("America/Montreal")).datetime
        actual = self.interpreter.get_new_event_from_string("Q1 S1S S1F")
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(2014, 1, 13, 7, tzinfo=tz.gettz("America/Montreal")).datetime
        expected_e = arrow.get(2014, 1, 20, 8, tzinfo=tz.gettz("America/Montreal")).datetime
        actual = self.interpreter.get_new_event_from_string("Q1 S2 S3F")
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(2014, 1, 13, 7, tzinfo=tz.gettz("America/Montreal")).datetime
        expected_e = arrow.get(2014, 1, 20, 8, tzinfo=tz.gettz("America/Montreal")).datetime
        actual = self.interpreter.get_new_event_from_string("H1 S2 S3F")
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(2014, 1, 8, 8, tzinfo=tz.gettz("America/Montreal")).datetime
        expected_e = arrow.get(2014, 1, 15, 7, tzinfo=tz.gettz("America/Montreal")).datetime
        actual = self.interpreter.get_new_event_from_string("Q1 P1F P2")
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(2014, 1, 8, 23, 45, tzinfo=tz.gettz("America/Montreal")).datetime
        expected_e = arrow.get(2014, 1, 14, 22, 23, tzinfo=tz.gettz("America/Montreal")).datetime
        actual = self.interpreter.get_new_event_from_string("Q1 [email protected]:45 [email protected]:23")
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(2014, 1, 8, 6, 59, tzinfo=tz.gettz("America/Montreal")).datetime
        expected_e = arrow.get(2014, 1, 18, 12, 23, tzinfo=tz.gettz("America/Montreal")).datetime
        actual = self.interpreter.get_new_event_from_string("Q1 P1-1m [email protected]:23")
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)

        expected_s = arrow.get(2014, 1, 1, 13, 20, tzinfo=tz.gettz("America/Montreal")).datetime
        expected_e = arrow.get(2014, 1, 18, 12, 23, tzinfo=tz.gettz("America/Montreal")).datetime
        actual = self.interpreter.get_new_event_from_string("Q1 [email protected]:20 [email protected]:23")
        actual_s = actual.get_start_datetime()
        actual_e = actual.get_end_datetime()
        self.assertEqual(expected_s, actual_s)
        self.assertEqual(expected_e, actual_e)
开发者ID:hubuhuan,项目名称:course-activity-planner,代码行数:104,代码来源:interpreter_test.py


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