ソースを参照

fixes #16

pull/24/head
theycallmemac 3年前
コミット
831dd63790
6個のファイルの変更152行の追加63行の削除
  1. +12
    -0
      scripts/lab_booking.py
  2. +8
    -62
      scripts/main.py
  3. +64
    -0
      scripts/opts.py
  4. +12
    -0
      scripts/room_booking.py
  5. +55
    -0
      scripts/utils.py
  6. +1
    -1
      setup.py

+ 12
- 0
scripts/lab_booking.py ファイルの表示

@@ -33,6 +33,18 @@ class LabBooking(object):
message = """From: %s\nTo: %s\nSubject: %s\n\n%s""" % (FROM, ", ".join(TO), SUBJECT, BODY)
return (FROM, TO), message


def confirm(self):
if int(sys.version[0]) < 3:
conf = raw_input("Is this information correct? (y/n): ")
else:
conf - input("Is this information correct? (y/n): ")
if conf == "y":
return conf
else:
return "n"


def send(self, FROM, TO, message):
try:
server = smtplib.SMTP("smtp.gmail.com", 587)


+ 8
- 62
scripts/main.py ファイルの表示

@@ -9,6 +9,8 @@ from lab_booking import LabBooking
from room_booking import RoomBooking
from lookup import LookUp
from now import Now
import utils
import opts

__author__ = "theycallmemac"
__version__ = '2.0.0'
@@ -18,8 +20,7 @@ __license__ = 'GPL-3.0'
def setup_options():
parser = OptionParser(
description='Displays info and books room around DCU.',
prog='dcurooms', version='%prog ' + __version__,
usage='%prog [option]')
prog='dcurooms', version='%prog ' + __version__, usage='%prog [option]')
parser.add_option(
"-l", "--lookup", action="store_true",
help="returns information given a specific room, week, day and hour")
@@ -39,7 +40,6 @@ def setup_options():
parser.add_option(
"-C", "--grattan", action="store_true",
help="displays the status of rooms in the Henry Grattan building")

return parser

def get_data():
@@ -52,71 +52,17 @@ def required():
times, c, g, details = get_data()
return parser, (options, arguments), (c, g), (times, details)

def get_lab_credentials():
email = input("Your gmail: ")
password = input("Your gmail password: ")
your_name = input("Your name: ")
society = input("Society name: ")
return email, password, your_name, society

def get_room_credentials():
name = input("Your name: ")
email = input("Your email: ")
number = input("Your number: ")
society = input("Society name: ")
return email, number, name, society

def get_lst(c, g, options):
if options.computing: lst = c
elif options.grattan: lst = g
return lst

def get_current_time(date):
day = date.weekday()
hour = date.hour
minute = date.minute
year, week_no, weekday = date.isocalendar()
start = 36
if week_no >= start:
offset = -start
else:
offset = 52 - start
week = week_no + offset - 1
return str(week), str(day + 1), str(hour), str(minute)

def main():
parser, (options, arguments), rooms, info = required()
if options.book and info[1][0][0] == "L":
email, password, your_name, society = get_lab_credentials()
lab = LabBooking(email, password, your_name, society, info[1])
emails, message = lab.draft()
print(message)
result = lab.send(emails[0], emails[1], message)
opts.booking_lab(info)
elif options.book and info[1][0][0] == "C":
email, number, name, society = get_room_credentials()
room = RoomBooking(email, number, name, society, info[1])
form = room.fill()
result = room.submit(form)
opts.booking_room(info)
if options.lookup and (options.grattan or options.computing):
lst = get_lst(rooms[0], rooms[1], options)
week, day, hour = info[1]
look = LookUp(week, day, hour)
look.check_args()
look.check_time(info[0])
look.building_option(lst)
opts.lookup_building(rooms, info, options)
elif options.lookup:
room, week, day, hour = info[1]
look = LookUp(week, day, hour)
look.check_args()
look.check_time(info[0])
look.room_option(room)
opts.lookup_room(info)
if options.now:
week, day, hour, minute = get_current_time(datetime.datetime.now())
now = Now(week, day, hour, minute)
now.round_it()
now.check_args()
now.check_time(info[0])
lst = get_lst(rooms[0], rooms[1], options)
now.building_option(lst, options)
opts.now()
if __name__ == "__main__":
main()

+ 64
- 0
scripts/opts.py ファイルの表示

@@ -0,0 +1,64 @@
import datetime
from optparse import OptionParser
from lab_booking import LabBooking
from room_booking import RoomBooking
from lookup import LookUp
from now import Now
import utils

__author__ = "theycallmemac"
__version__ = '2.0.0'
__copyright__ = 'Copyright (c) 2018 theycallmemac'
__license__ = 'GPL-3.0'

def get_lab_credentials():
return utils.get_version_email()

def get_room_credentials():
return utils.get_version_form()

def booking_lab(info):
email, password, your_name, society = get_lab_credentials()
lab = LabBooking(email, password, your_name, society, info[1])
emails, message = lab.draft()
print(message)
conf = lab.confirm()
if conf == "y":
result = lab.send(emails[0], emails[1], message)
else:
"Booking cancelled."

def booking_room(info):
email, number, name, society = get_room_credentials()
room = RoomBooking(email, number, name, society, info[1])
form = room.fill()
conf = room.confirm()
if conf == "y":
result = room.submit(form)
else:
"Booking cancelled."

def lookup_building(rooms, info, options):
lst = utils.get_lst(rooms[0], rooms[1], options)
week, day, hour = info[1]
look = LookUp(week, day, hour)
look.check_args()
look.check_time(info[0])
look.building_option(lst)

def lookup_room(info):
room, week, day, hour = info[1]
look = LookUp(week, day, hour)
look.check_args()
look.check_time(info[0])
look.room_option(room)

def now():
week, day, hour, minute = utils.get_current_time(datetime.datetime.now())
now = Now(week, day, hour, minute)
now.round_it()
now.check_args()
now.check_time(info[0])
lst = utils.get_lst(rooms[0], rooms[1], options)
now.building_option(lst, options)


+ 12
- 0
scripts/room_booking.py ファイルの表示

@@ -47,6 +47,18 @@ class RoomBooking(object):
browser["submitted[email_address]"] = self.email
return browser

def confirm(self):
if int(sys.version[0]) < 3:
conf = raw_input("Is this information correct? (y/n): ")
else:
conf - input("Is this information correct? (y/n): ")

if conf == "y":
return conf
else:
return "n"


def submit(self, form):
request = form.request
response = form.submit_selected()


+ 55
- 0
scripts/utils.py ファイルの表示

@@ -0,0 +1,55 @@
import datetime
import sys

__author__ = "theycallmemac"
__version__ = '2.0.0'
__copyright__ = 'Copyright (c) 2018 theycallmemac'
__license__ = 'GPL-3.0'


def get_lst(c, g, options):
if options.computing: lst = c
elif options.grattan: lst = g
return lst

def get_current_time(date):
day = date.weekday()
hour = date.hour
minute = date.minute
year, week_no, weekday = date.isocalendar()
start = 36
if week_no >= start:
offset = -start
else:
offset = 52 - start
week = week_no + offset - 1
return str(week), str(day + 1), str(hour), str(minute)

def get_version_email():
if int(sys.version[0]) < 3:
email = raw_input("Your gmail: ")
password = raw_input("Your gmail password: ")
your_name = raw_input("Your name: ")
society = raw_input("Society name: ")
return email, password, your_name, society
else:
email = str(input("Your gmail: "))
password = input("Your gmail password: ")
your_name = input("Your name: ")
society = input("Society name: ")
return email, password, your_name, society


def get_version_form():
if int(sys.version[0]) < 3:
name = raw_input("Your name: ")
email = raw_input("Your email: ")
number = raw_input("Your number: ")
society = raw_input("Society name: ")
return email, number, name, society
else:
name = string(input("Your name: "))
email = input("Your email: ")
number = input("Your number: ")
society = input("Society name: ")
return email, number, name, society

+ 1
- 1
setup.py ファイルの表示

@@ -7,7 +7,7 @@ setup(name='dcurooms',
author='theycallmemac',
url='https://github.com/theycallmemac/dcurooms',
license='GPL-3.0',
scripts=['scripts/dcurooms', 'scripts/main.py', 'scripts/lab_booking.py', 'scripts/room_booking.py', 'scripts/lookup.py', 'scripts/now.py'],
scripts=['scripts/dcurooms', 'scripts/main.py', 'scripts/utils.py', 'scripts/opts.py', 'scripts/lab_booking.py', 'scripts/room_booking.py', 'scripts/lookup.py', 'scripts/now.py'],
install_requires=[
'MechanicalSoup', 'bs4', 'requests'
],


読み込み中…
キャンセル
保存