Implement RegEx Groups to Event object parsing

Also renamed some of the dialog files
This commit is contained in:
Xevion
2021-08-25 06:33:26 -05:00
parent d447dfb343
commit 0d6909a9b1
3 changed files with 147 additions and 2 deletions

View File

@@ -2,10 +2,11 @@ from __future__ import print_function
import datetime
import os.path
import re
import traceback
from typing import Any, Iterator, List, Optional, Tuple, Union
from PyQt5 import QtCore, QtGui
from PyQt5 import QtGui
from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem
from dateutil.parser import isoparse
from google.auth.transport.requests import Request
@@ -16,6 +17,9 @@ from tzlocal import get_localzone
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/calendar']
TIME_REGEX = re.compile(r'\d{2}:\d{2}(?:AM|PM)')
DATE_FORMAT = '%Y-%m-%d'
DATETIME_FORMAT = DATE_FORMAT + ' %H:%M%p'
class Calendar(object):
@@ -134,3 +138,20 @@ class Event(object):
table.setItem(row, 1, QTableWidgetItem('Foreign'))
table.setItem(row, 2, QTableWidgetItem(self.start.strftime(formatString)))
table.setItem(row, 3, QTableWidgetItem(self.end.strftime(formatString)))
@classmethod
def parse_raw(self, input: Tuple[str]) -> 'Event':
"""Takes in input that has been separated by a RegEx expression into groups and creates a Event object"""
first_time = re.match(TIME_REGEX, input[2]) is not None
second_time = re.match(TIME_REGEX, input[3 + (1 if first_time else 0)])
second_index = 2 + (1 if first_time else 0) # Shortcut
# Yeah this logic is really scuffed, but I really don't have a better way right now
start = datetime.datetime.strptime(DATETIME_FORMAT if first_time else DATE_FORMAT,
input[1] + (input[second_index - 1] if first_time else ''))
end = datetime.datetime.strptime(DATETIME_FORMAT if second_time else DATE_FORMAT,
input[second_index] + (input[second_index + 1] if second_time else ''))
return Event(
summary=input[0],
start=start,
end=end
)

124
bulk_reminders/gui.ui Normal file
View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>672</width>
<height>553</height>
</rect>
</property>
<property name="windowTitle">
<string>Bulk Reminders</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QTableWidget" name="eventsView"/>
</item>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="loadEventsButton">
<property name="text">
<string>Load events</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="submitButton">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Submit</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="calendarCombobox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>140</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="eventCountLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>34 ready, 26 undoable in 3 stages, 18 prexisting (94)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>30</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="undoButton">
<property name="text">
<string>Undo</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>672</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -14,7 +14,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>OAuth 2.0 Flow</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>