Skip to content

Commit

Permalink
auto populate config file in home directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinny committed Oct 21, 2015
1 parent 51ae50d commit aa625f9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
10 changes: 0 additions & 10 deletions settings.py

This file was deleted.

9 changes: 5 additions & 4 deletions uvaclient.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import requests
from bs4 import BeautifulSoup
import getpass
import settings
from uvasettings import uvasettings
import uvaapi as api
import udebug
import headers
import utils

settings = uvasettings()

'''
Main level of abstraction for interfacing with UVa.
Expand All @@ -22,7 +24,7 @@ def __init__(self):
# Create a session for making requests
# Nessesary to persist login information
self.session = requests.Session()
self.username = settings.username
self.username = settings['username']
self.uid = api.get_uid(self.username)

def prompt_password(self):
Expand Down Expand Up @@ -71,8 +73,7 @@ def get_problem_name(self, problem_num):

# Submits a problem with the given parameters
# Must be logged in for this to work
# see settings.py for a list of language codes
def submit(self, problemid, f, language = settings.language):
def submit(self, problemid, f, language = settings['language']):
data = {
"localid": problemid,
"code": open(f, "r").read(),
Expand Down
31 changes: 31 additions & 0 deletions uvasettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from os.path import expanduser
import json
import utils

SETTINGS_PATH = expanduser("~") + "/.uvashell"

class uvasettings():
def __init__(self):
try:
home = expanduser("~")
f = open(home + "/.uvashell", "r")
self.d = json.loads(f.read())
except Exception as e:
self.d = self.prompt_info()
utils.write_file(expanduser("~") + "/.uvashell", json.dumps(self.d))

def prompt_info(self):
print "uva username:"
username = raw_input()

print "default submission language:"
language = raw_input()

ret = {
'username': username,
'language': language
}
return ret;

def __getitem__(self, i):
return self.d[i]

0 comments on commit aa625f9

Please sign in to comment.