Pārlūkot izejas kodu

made fixes to several issues

pull/24/head
theycallmemac pirms 3 gadiem
vecāks
revīzija
4db0593b39
8 mainītis faili ar 57 papildinājumiem un 33 dzēšanām
  1. +1
    -0
      .travis.yml
  2. +1
    -1
      scripts/lab_booking.py
  3. +5
    -2
      scripts/lookup.py
  4. +3
    -4
      scripts/main.py
  5. +8
    -5
      scripts/now.py
  6. +1
    -1
      scripts/room_booking.py
  7. +21
    -20
      scripts/utils.py
  8. +17
    -0
      tests/test_now.py

+ 1
- 0
.travis.yml Parādīt failu

@@ -10,6 +10,7 @@ install:
script:
- python tests/test_lookup_output.py
- python tests/test_available_now_output.py
- python tests/test_now.py

notifications:
email: false

+ 1
- 1
scripts/lab_booking.py Parādīt failu

@@ -30,7 +30,7 @@ class LabBooking(object):
self.arguments[1] + " from " + self.arguments[2][:2] + ":" + \
self.arguments[2][2:] + " to " + self.arguments[3][:2] + ":" + \
self.arguments[3][2:] + " for " + self.society + ".\n\nThank you,\n" + self.name + "."
message = """From: %s\nTo: %s\nSubject: %s\n\n%s""" % (FROM, ", ".join(TO), SUBJECT, BODY)
message = """\nFrom: %s\nTo: %s\nSubject: %s\n\n%s""" % (FROM, ", ".join(TO), SUBJECT, BODY)
return (FROM, TO), message




+ 5
- 2
scripts/lookup.py Parādīt failu

@@ -3,7 +3,7 @@ from mechanicalsoup import StatefulBrowser
from requests import get
from bs4 import BeautifulSoup
import utils
from termcolor import colored
if sys.version_info[0] < 3:
from cookielib import LWPCookieJar
else:
@@ -38,7 +38,10 @@ class LookUp(object):
def building_option(self, lst):
for room in lst:
status = LookUp.build_timetable(self, room)
print(room + ": " + status)
if len(status) <= 9:
print("\033[1;92m{0}\033[00m".format(room) + ": " + "\033[1;97m{0}\033[00m".format(status))
else:
print("\033[1;91m{0}\033[00m".format(room) + ": " + "\033[1;90m{0}\033[00m".format(status))

def room_option(self, room):
status = LookUp.build_timetable(self, room)


+ 3
- 4
scripts/main.py Parādīt failu

@@ -19,11 +19,10 @@ __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]')
description="\033[1;97m{0}\033[00m".format('Displays info and books room around DCU.'),
prog="\033[1;97m{0}\033[00m".format('dcurooms'), version='%prog ' + __version__, usage='%prog [' + '\033[1;92m{0}\033[00m'.format("option") + ']')
parser.add_option(
"-l", "--lookup", action="store_true",
help="returns information given a specific room, week, day and hour")
"-l", "--lookup", action="store_true", help="returns information given a specific room, week, day and hour")
parser.add_option(
"-b", "--book", action="store_true",
help="books a room by providing the room, D/M/YYYY, start, and end")


+ 8
- 5
scripts/now.py Parādīt failu

@@ -29,14 +29,14 @@ class Now(object):

def check_args(self):
if int(self.week) not in range(1, 53) or int(self.day) not in range(1, 7):
print("Incorrect parameters passed.")
print("\033[1;91m{0}\033[00m".format("Incorrect parameters passed."))
sys.exit()
else:
pass

def round_it(self):
if int(self.hour) < 8 or int(self.hour) >= 23:
print("Outside scheduled timetables. Try again at 08:00.")
print("\033[1;93m{0}\033[00m".format("Outside scheduled timetables. Try again at 08:00."))
sys.exit()
if int(self.minute) >= 30:
self.minute = '30'
@@ -46,7 +46,7 @@ class Now(object):
def check_time(self, times):
time = self.hour + self.minute
if time not in times:
print("Outside scheduled timetables. Please try again at 08:00.")
print("\033[1;93m{0}\033[00m".format("Outside scheduled timetables. Please try again at 08:00."))
sys.exit()
for k, v in times.items():
if k == self.hour:
@@ -59,9 +59,12 @@ class Now(object):
def get_status(self, options, room, status):
if options.available:
if len(status) <= 9:
print(room + ": " + status)
print("\033[1;92m{0}\033[00m".format(room) + ": " +"\033[1;97m{0}\033[00m".format(status))
elif len(status) > 9:
print("\033[1;91m{0}\033[00m".format(room) + ": " +"\033[1;90m{0}\033[00m".format(status))
else:
print(room + ": " + status)
print("\033[1;92m{0}\033[00m".format(room) + ": " +"\033[1;97m{0}\033[00m".format(status))


def building_option(self, lst, options):
for room in lst:


+ 1
- 1
scripts/room_booking.py Parādīt failu

@@ -33,7 +33,7 @@ class RoomBooking(object):
room, date, start, end = self.arguments[0], self.arguments[1].split("/"), self.arguments[2][:2] + ":" + self.arguments[2][2:], self.arguments[3][:2] + ":" + self.arguments[3][2:]
day, month, year = date[0], date[1], date[2]
browser.open("http://www.dcu.ie/registry/booking.shtml")
browser.select_form(nr=2)
browser.select_form(nr=4)
browser["submitted[name_of_club_society]"] = self.society
browser["submitted[name_of_person_making_booking]"] = self.name
browser["submitted[contact_telephone_number]"] = self.number


+ 21
- 20
scripts/utils.py Parādīt failu

@@ -2,6 +2,7 @@ import datetime
import sys
from requests import get
from bs4 import BeautifulSoup
import getpass

__author__ = "theycallmemac"
__version__ = '2.0.0'
@@ -10,9 +11,9 @@ __license__ = 'GPL-3.0'

def confirm():
if int(sys.version[0]) < 3:
conf = raw_input("Is this information correct? (y/n): ")
conf = raw_input("\033[1;93m{0}\033[00m".format("\nIs this information correct? (y/n): "))
else:
conf = input("Is this information correct? (y/n): ")
conf = input("\033[1;93m{0}\033[00m".format("\nIs this information correct? (y/n): "))
if conf == "y":
return conf
else:
@@ -21,7 +22,7 @@ def confirm():

def check_args(week, day):
if int(week) not in range(1, 53) or int(day) not in range(1, 7):
print("Incorrect parameters passed.")
print("\033[1;91m{0}\033[00m".format("Incorrect parameters passed."))
sys.exit()
else:
pass
@@ -48,33 +49,33 @@ def get_current_time(date):
else:
offset = 52 - start
week = week_no + offset - 1
return str(week), str(day + 1), str(hour), str(minute)
return str(week), str(day + 1), str(hour - 2), 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: ")
email = raw_input("\033[1;97m{0}\033[00m".format("Your gmail: "))
password = getpass.getpass("\033[1;97m{0}\033[00m".format("Your gmail password: "))
your_name = raw_input("\033[1;97m{0}\033[00m".format("Your name: "))
society = raw_input("\033[1;97m{0}\033[00m".format("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: ")
email = input("\033[1;97m{0}\033[00m".format("Your gmail: "))
password = getpass.getpass("\033[1;97m{0}\033[00m".format("Your gmail password: "))
your_name = input("\033[1;97m{0}\033[00m".format("Your name: "))
society = input("\033[1;97m{0}\033[00m".format("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: ")
name = raw_input("\033[1;97m{0}\033[00m".format("Your name: "))
email = raw_input("\033[1;97m{0}\033[00m".format("Your email: "))
number = raw_input("\033[1;97m{0}\033[00m".format("Your number: "))
society = raw_input("\033[1;97m{0}\033[00m".format("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: ")
name = input("\033[1;97m{0}\033[00m".format("Your name: "))
email = input("\033[1;97m{0}\033[00m".format("Your email: "))
number = input("\033[1;97m{0}\033[00m".format("Your number: "))
society = input("\033[1;97m{0}\033[00m".format("Society name: "))
return email, number, name, society

+ 17
- 0
tests/test_now.py Parādīt failu

@@ -0,0 +1,17 @@
import unittest
import sys
import datetime
import os
sys.path.append('.')
from scripts.utils import get_current_time
class RequiredTestCase(unittest.TestCase):
def test_time(self):
now = get_current_time(datetime.datetime.now())
hr = int(now[2]) + 2
mn = int(now[3])
hr_d = datetime.datetime.now().hour
mn_d = datetime.datetime.now().minute
self.assertTrue(hr == hr_d and mn == mn_d)
if __name__ == '__main__':
unittest.main()


Notiek ielāde…
Atcelt
Saglabāt