· 4 years ago · May 06, 2021, 06:56 PM
1from __future__ import print_function
2import kivy
3from kivy.app import App
4from kivy.uix.button import Button
5from kivy.uix.boxlayout import BoxLayout
6from kivy.core.window import Window
7from kivy.config import Config
8from kivy.uix.image import Image
9from kivy.uix.label import Label
10from kivy.uix.textinput import TextInput
11import easygui
12import pytesseract
13from GoogleTasks import createService, displayTaskList, createTaskList, createTask
14from GoogleService import convert_to_RFC_datetime
15
16CREDENTIALS = 'credentials.json' #The credintals file goes here
17API_NAME = 'tasks' #The name of the Google API being used, in this case it's tasks
18API_VERSION = 'v1' #The version of said api
19SCOPES = ['https://www.googleapis.com/auth/tasks'] #The scope for said API
20kivy.require("2.0.0")
21
22filename = ""
23
24
25class MainApp(BoxLayout):
26 def getDate(self, fileText):
27 substring = "Due"
28
29 if substring in fileText:
30 print("Found in string")
31 else:
32 print("Not found in string")
33
34 startIndexDate = fileText.index(substring)
35 endIndexDate = fileText.index("at")
36
37 dateString = fileText[startIndexDate + 4: endIndexDate]
38 return dateString
39
40 def getTime(self, fileText):
41 startIndexTime = fileText.index("at")
42 endIndexTime = fileText.index("|")
43
44 timeString = fileText[startIndexTime + 3: endIndexTime]
45 return timeString
46
47 def getAssignmentName(self, fileText):
48 startIndexName = 0
49 endIndexName = 0
50
51 if "Available" in fileText:
52 print("available has been found!")
53 endIndexName = fileText.index("Available")
54 elif "Not available" in fileText:
55 print("not available has been found!")
56 endIndexName = fileText.index("Not available")
57 elif "Due" in fileText:
58 print("due has been found!")
59 endIndexName = fileText.index("Due")
60
61 nameString = fileText[startIndexName + 3: endIndexName]
62 print("this line has been reached!")
63 return nameString
64
65 def monthConversion(self, month):
66 monthNumber = 0
67 if month == "Jan":
68 monthNumber = 1
69 elif month == "Feb":
70 monthNumber = 2
71 elif month == "Mar":
72 monthNumber = 3
73 elif month == "Apr":
74 monthNumber = 4
75 elif month == "May":
76 monthNumber = 5
77 elif month == "Jun":
78 monthNumber = 6
79 elif month == "Jul":
80 monthNumber = 7
81 elif month == "Aug":
82 monthNumber = 8
83 elif month == "Sep":
84 monthNumber = 9
85 elif month == "Oct":
86 monthNumber = 10
87 elif month == "Nov":
88 monthNumber = 11
89 elif month == "Dec":
90 monthNumber = 12
91 return monthNumber
92
93
94 def fileConversion(self, value):
95
96#
97# This code is used to pull a file and convert that file to a string.
98#
99 print("this line was printed!")
100 filename = easygui.fileopenbox()
101 pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract'
102 fileText = pytesseract.image_to_string(filename)
103#
104# TODO: Slice up the fileText string into several "line strings" so that we can pull information for each individual lines.
105# Make sure to store each line in a list.
106#
107 amountofDue = fileText.count("Due")
108 print(amountofDue)
109
110#
111# This code is used to call the methods above, and retrieve the key pieces of the selected line.
112#
113 print(fileText)
114
115 dateString = self.getDate(fileText)
116 print(dateString)
117
118 nameString = self.getAssignmentName(fileText)
119
120 monthString = dateString[0:3]
121 dayString = dateString[4:len(dateString)]
122
123 monthNumber = self.monthConversion(monthString)
124 dayNumber = int(dayString)
125 print(monthNumber)
126 print(dayNumber)
127
128#
129# This code is used to insert the variables into a the API to create a google task
130#
131 dt = convert_to_RFC_datetime(2021, monthNumber, dayNumber, 0, 0)
132
133 taskListID = createTaskList("Operating Systems and Networking")
134 createTask(taskListID, nameString, "", dt, "needsAction", False)
135
136
137 def __init__(self, **kwargs):
138 createService(CREDENTIALS, API_NAME, API_VERSION, SCOPES)
139
140 super().__init__(**kwargs)
141 self.orientation = "vertical"
142
143 Logo = Image(source='Logo.png')
144 self.add_widget(Logo)
145
146 Text = Label(text='Create Class List')
147 self.add_widget(Text)
148
149 InputBox = TextInput(text='hello world!')
150 self.add_widget(InputBox)
151
152 UploadButton = Button(text="Upload File", font_size = 14)
153
154 test = UploadButton.bind(on_press=self.fileConversion)
155 self.add_widget(UploadButton)
156
157 Window.clearcolor = (1, 1, 1, 1)
158 Window.size = (300, 650)
159 App.title = "CanSync"
160 Config.set('kivy', 'window_icon', 'C:/Users/User/PycharmProjects/TestProject/Python Files/CanSyncIcon.ico')
161 Config.set('graphics', 'resizable', '0')
162 Config.write()
163
164
165class BuildApp(App):
166 def build(self):
167 return MainApp()
168
169if __name__ == "__main__":
170 BuildApp().run()