Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from Frequency import FrequencyType
from Subscription import Subscription
from Content import ContentType
from User import User
session = {}
def welcomeScreen():
while True:
print('\n1 - Sign Up')
print('2 - Log In')
print('3 - Exit')
option = int(input('Please input your choice: '))
if option == 1:
username = input('\nPlease enter your username: ')
email = input('Please enter your email address: ')
try:
User().createUser(username, email)
print('\nUser created! - Please log in.')
welcomeScreen()
break
except Exception as e:
# print('\nPlease try again.')
print(e)
elif option == 2:
if 'username' not in session:
username = input('\nPlease enter your username: ')
if User().validateUser(username):
session['username'] = username
print('{0}, you have been logged in!'.format(username))
menu()
else:
print('\nInvalid username - please try again.')
welcomeScreen()
break
else:
menu()
break
elif option == 3:
print('\nThank you - goodbye.')
break
def menu():
while True:
print('\n1 - Subscribe to content')
print('2 - View subscriptions')
print('3 - Change subscription preferences')
print('4 - Log out')
print('5 - Exit')
option = int(input('\nYour choice: '))
if option == 1:
print('\nHere are our content options: \n')
contentOptions = len(ContentType) + 1
for l in range(1, contentOptions):
print('{0} - {1}'.format(l, ContentType(l).name))
print('\n{0} - Back'.format(contentOptions))
contentOption = int(input('\nPlease select a content option: '))
if contentOption not in range(1, contentOptions + 1):
print("Invalid content option.")
else:
if contentOption != contentOptions:
if not subscribeToContent(contentOption):
print('\nA subscription for {0} already exists.'.format(ContentType(l).name))
print("\nUse the 'Change your subscription preferences' menu option to change it.")
else:
print('\nSubscribed to {0}!'.format(ContentType(contentOption).name))
elif option == 2:
subscriptions = Subscription().getAllSubscriptions(session['username'])
if subscriptions:
for subscription in subscriptions:
print('{0} - {1}'.format(subscription['contentType'],
subscription['frequency']))
else:
print('\nYou have no subscriptions.')
elif option == 3:
subscriptions = Subscription().getAllSubscriptions(session['username'])
if not subscriptions:
print('\nYou have no subscriptions.')
else:
print('\nWhich subscription would you like to edit?')
for i in range(len(subscriptions)):
print('{0} - {1}'.format((i + 1), subscriptions[i]['contentType']))
print('\n{0} - Back'.format(len(subscriptions) + 1))
subOption = int(input('\nPlease select a subscription option: '))
print('\nSelected subscription - {0}'.format(subscriptions[subOption - 1]['contentType']))
if subOption < len(subscriptions) + 1:
print('\nFrequency options: ')
for e in range(1, len(FrequencyType) + 1):
print('{0} - {1}'.format(e, FrequencyType(e).name))
freqOption = int(input('\nSelect the frequency you want for your {0} subscription?: '
.format(subscriptions[subOption - 1]['contentType'])))
if freqOption not in range(1, len(FrequencyType) + 1):
print('Invalid frequency option')
else:
Subscription().updateSubscription(session['username'],
ContentType[subscriptions[subOption - 1]['contentType']], FrequencyType(freqOption))
print('Your {0} subscription has been updated.'.format(subscriptions[subOption - 1]['contentType']))
elif subOption > len(subscriptions) + 1:
print('Invalid option selected')
elif option == 4:
del session['username']
print('\nYou have been logged out.')
break
elif option == 5:
break
def subscribeToContent(contentOption):
if not Subscription().validateSubscription(session['username'], ContentType(contentOption).name):
Subscription().createSubscription(session['username'], ContentType(contentOption), FrequencyType.ONCE_PER_DAY)
return True
return False
def start():
print('******** WELCOME TO THE CRYPTO NEWS SERVICE ********\n')
welcomeScreen()
start()