Skip to content

Commit 36b677a

Browse files
committed
feat: add command line option for continuous loop
1 parent f3aa4c0 commit 36b677a

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

middag.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from __future__ import print_function
22
import datetime
3+
from re import T
34
import time
45
import pickle
56
import os.path
7+
import sys, getopt
8+
69
from googleapiclient.discovery import build
710
from google_auth_oauthlib.flow import InstalledAppFlow
811
from google.auth.transport.requests import Request
@@ -40,7 +43,22 @@ def dayText(event):
4043

4144
return text
4245

43-
def main():
46+
def main(argv):
47+
loop = None
48+
try:
49+
opts, args = getopt.getopt(argv,"hm:",["help ","mode ="])
50+
except getopt.GetoptError:
51+
print('middag.py -m <loop>')
52+
sys.exit(2)
53+
for opt, arg in opts:
54+
if opt in ('-h', '--help'):
55+
print('middag.py -m <loop>')
56+
sys.exit()
57+
elif opt in ("-m", "--mode"):
58+
if arg in ('loop'):
59+
loop = True
60+
61+
print (loop)
4462
"""Shows basic usage of the Google Calendar API.
4563
Prints the start and name of the next 10 events on the user's calendar.
4664
"""
@@ -71,7 +89,7 @@ def main():
7189
print("Created device")
7290

7391
start = time.perf_counter()
74-
while (start + 550) > time.perf_counter():
92+
while (start + 550) > time.perf_counter() or loop:
7593
# Call the Calendar API
7694
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
7795
# print('Getting the upcoming 10 events')
@@ -91,4 +109,4 @@ def main():
91109
time.sleep(2)
92110

93111
if __name__ == '__main__':
94-
main()
112+
main(sys.argv[1:])

0 commit comments

Comments
 (0)