def post(self): # parser arguments parser.add_argument('uid', type=str, required=True) parser.add_argument('ibu', type=str, required=True) parser.add_argument('calories', type=int, required=True) parser.add_argument('abv', type=str, required=True) parser.add_argument('brewery', type=str, required=True) parser.add_argument('style', type=str, required=True) args = parser.parse_args() # Get timestamp of addition current_time = time.time() current_timestamp = datetime.datetime.fromtimestamp( current_time).strftime('%Y-%m-%d %H:%M:%S') # Validate user & beer userExists = user.getUsers(args['uid'], 1) added_beer = beer.checkAdd(args['uid']) if userExists == None: return {"Message": "User does not exist."} if added_beer != None: return {"Message": "User has already added a beer today."} # Increment id self.beer_id = beer.getAmt() + 1 # Add new beer to DB details = (self.beer_id, args['ibu'], args['calories'], args['abv'], args['brewery'], args['style'], args['uid'], current_timestamp) beer.addBeer(details) # Add to BEER dict BEER[int(self.beer_id)] = { 'IBU': args['ibu'], 'Calories': args['calories'], 'ABV': args['abv'], 'Brewery': args['brewery'], 'Style': args['style'], 'UID': args['uid'], 'Date': str(current_timestamp) } # Remove arguments from parser parser.remove_argument('uid') parser.remove_argument('ibu') parser.remove_argument('calories') parser.remove_argument('abv') parser.remove_argument('brewery') parser.remove_argument('style') return BEER[self.beer_id], 201
def post(self): # parser arguments parser.add_argument('uid', type=int, required=True) parser.add_argument('beerid', type=int, required=True) parser.add_argument('aroma', type=int, required=True) parser.add_argument('appearance', type=int, required=True) parser.add_argument('taste', type=int, required=True) args = parser.parse_args() # Validate aroma, appearance, and taste if int(args['aroma']) > 5 or int(args['appearance']) > 5 or int(args['taste']) > 10: return {"Message": "Invalid value for aroma, appearance, or taste"} # Validate user & beer userExists = user.getUsers(args['uid'], 1) beerExists = beer.getBeers(args['beerid'], 1) if userExists == None or beerExists == None: return {"Message": "User or Beer does not exist."} # Increment id self.review_id = review.getAmt() + 1 # Calculate overall score self.overall = int(args['aroma']) + int(args['appearance']) + int(args['taste']) # Add to DB details = (self.review_id, args['uid'], args['beerid'], args['aroma'], args['appearance'], args['taste'], self.overall) review.addReview(details) # Add to REVIEWS dict REVIEWS[int(self.review_id)] = {'UID': args['uid'], 'Beer': args['beerid'], 'Aroma': args['aroma'], 'Appearance': args['appearance'], 'Taste': args['taste'], 'Overall': self.overall} # Add Review to BEERS dict BEER[int(args['beerid'])]['Reviews'].append({'Aroma': args['aroma'], 'Appearance': args['appearance'], 'Taste': args['taste'], 'Overall': self.overall, 'User': args['uid']}) # Remove arguments from parser parser.remove_argument('uid') parser.remove_argument('beerid') parser.remove_argument('aroma') parser.remove_argument('appearance') parser.remove_argument('taste') return REVIEWS[self.review_id], 201
def post(self): # parser arguments parser.add_argument('uid', type=str, required=True) parser.add_argument('ibu', type=str, required=True) parser.add_argument('calories', type=int, required=True) parser.add_argument('abv', type=str, required=True) parser.add_argument('brewery', type=str, required=True) parser.add_argument('style', type=str, required=True) args = parser.parse_args() # Get timestamp of addition current_time = time.time() current_timestamp = datetime.datetime.fromtimestamp(current_time).strftime('%Y-%m-%d %H:%M:%S') # Validate user & beer userExists = user.getUsers(args['uid'], 1) added_beer = beer.checkAdd(args['uid']) if userExists == None: return {"Message": "User does not exist."} if added_beer != None: return {"Message": "User has already added a beer today."} # Increment id self.beer_id = beer.getAmt()+1 # Add new beer to DB details = (self.beer_id, args['ibu'], args['calories'], args['abv'], args['brewery'], args['style'], args['uid'], current_timestamp) beer.addBeer(details) # Add to BEER dict BEER[int(self.beer_id)] = {'IBU': args['ibu'], 'Calories': args['calories'], 'ABV': args['abv'], 'Brewery': args['brewery'], 'Style': args['style'], 'UID': args['uid'], 'Date': str(current_timestamp)} # Remove arguments from parser parser.remove_argument('uid') parser.remove_argument('ibu') parser.remove_argument('calories') parser.remove_argument('abv') parser.remove_argument('brewery') parser.remove_argument('style') return BEER[self.beer_id], 201
def user_get(): if request.method == 'GET': results = getUsers() return jsonify({'results': results}), 200 elif request.method == 'POST': user_name = str(request.json['user_name']) password = str(request.json['password']) role_id = str(request.json['role_id']) results = {'user_name': user_name, 'role_id': role_id} try: saveUser(user_name, password, role_id) except Exception as e: print(str(e)) print("ERROR inserting into role") abort(400) return jsonify({'results': results}), 200 elif request.method == 'PUT': user_id = str(request.json['user_id']) user_name = str(request.json['user_name']) password = str(request.json['password']) role_id = str(request.json['role_id']) results = { 'user_id': user_id, 'user_name': user_name, 'role_id': role_id } try: updateUser(user_id, user_name, password, role_id) except Exception as e: print("ERROR update into role") abort(400) return jsonify({'results': results}), 200
r4vByAuthors[author] = set() r4vByAuthors[author].add(tid) print status + ':' for a in r4vByAuthors: print a, len(r4vByAuthors[a]) searchCriterias = [{ 'desc': '5月31号以后所有任务', 'args': dict( constraints={ #"projects": ["儿童脑适能"], #"statuses":["open", "r4v"], "modifiedStart": int( datetime.strptime('2017-05-31 00:00', '%Y-%m-%d %H:%M').strftime("%s")), }), }] criteria = searchCriterias[0] resp = fab.maniphest.search(**criteria['args']).data resp = fab.maniphest.gettasktransactions( ids=map(lambda x: x['id'], resp)).response users = getUsers(fab) with CacheUsers(users): ui = UserInfo() reportStatus(resp, 'r4v', ui) reportStatus(resp, 'resolved', ui)
r4vByAuthors = {} for tid in taskTrans: trans = taskTrans[tid] for t in filter(lambda x: x['transactionType'] == 'status' and x['newValue'] == status, trans): author = ui.phid2realname(t['authorPHID']) if author not in r4vByAuthors: r4vByAuthors[author] = set() r4vByAuthors[author].add(tid) print status + ':' for a in r4vByAuthors: print a, len(r4vByAuthors[a]) searchCriterias = [ { 'desc': '5月31号以后所有任务', 'args': dict(constraints = { #"projects": ["儿童脑适能"], #"statuses":["open", "r4v"], "modifiedStart": int(datetime.strptime('2017-05-31 00:00', '%Y-%m-%d %H:%M').strftime("%s")), }), } ] criteria = searchCriterias[0] resp = fab.maniphest.search(**criteria['args']).data resp = fab.maniphest.gettasktransactions(ids = map(lambda x: x['id'], resp)).response users = getUsers(fab) with CacheUsers(users): ui = UserInfo() reportStatus(resp, 'r4v', ui) reportStatus(resp, 'resolved', ui)
import json import settings ############################################################################################### ############################################################################################### ##Login LogIn = logIn(settings.GDHostname,settings.GDAdmin_username , settings.GDAdmin_password) GDCAuthSST = LogIn['GDCAuthSST'] #Get SST adminid = LogIn['Profile'] #Get Profile of loged user GDCAuthTT= getTT(settings.GDHostname,GDCAuthSST) #set Variable GDCAuthTT GetDomainUsers=getUsers(settings.GDHostname,GDCAuthTT,settings.GDDomain) json_acceptable_string = GetDomainUsers['read'].replace("'", "\"") d = json.loads(json_acceptable_string) iterace = d['accountSettings']['items'] for item in iterace: res=ChangeUserSSO(settings.GDHostname,GDCAuthTT,item['accountSetting']['links']['self'],"gooddata.jiri.simon",item['accountSetting']['firstName'],item['accountSetting']['lastName']) print res['code'] print res['read'] userDetail = gedUserDetail(settings.GDHostname,GDCAuthTT,adminid.split('/', 4 )[4]) print json.loads(userDetail['read'])['accountSetting']['links']['self'] print json.loads(userDetail['read'])['accountSetting']['firstName'] print json.loads(userDetail['read'])['accountSetting']['lastName'] print json.loads(userDetail['read'])['accountSetting']['ssoProvider']
def post(self): # parser arguments parser.add_argument('uid', type=int, required=True) parser.add_argument('beerid', type=int, required=True) parser.add_argument('aroma', type=int, required=True) parser.add_argument('appearance', type=int, required=True) parser.add_argument('taste', type=int, required=True) args = parser.parse_args() # Validate aroma, appearance, and taste if int(args['aroma']) > 5 or int(args['appearance']) > 5 or int( args['taste']) > 10: return {"Message": "Invalid value for aroma, appearance, or taste"} # Validate user & beer userExists = user.getUsers(args['uid'], 1) beerExists = beer.getBeers(args['beerid'], 1) if userExists == None or beerExists == None: return {"Message": "User or Beer does not exist."} # Increment id self.review_id = review.getAmt() + 1 # Calculate overall score self.overall = int(args['aroma']) + int(args['appearance']) + int( args['taste']) # Add to DB details = (self.review_id, args['uid'], args['beerid'], args['aroma'], args['appearance'], args['taste'], self.overall) review.addReview(details) # Add to REVIEWS dict REVIEWS[int(self.review_id)] = { 'UID': args['uid'], 'Beer': args['beerid'], 'Aroma': args['aroma'], 'Appearance': args['appearance'], 'Taste': args['taste'], 'Overall': self.overall } # Add Review to BEERS dict BEER[int(args['beerid'])]['Reviews'].append({ 'Aroma': args['aroma'], 'Appearance': args['appearance'], 'Taste': args['taste'], 'Overall': self.overall, 'User': args['uid'] }) # Remove arguments from parser parser.remove_argument('uid') parser.remove_argument('beerid') parser.remove_argument('aroma') parser.remove_argument('appearance') parser.remove_argument('taste') return REVIEWS[self.review_id], 201
i[4], 'Style': i[5], 'UID': i[6], 'Date': str(i[7]), 'Reviews': [{ 'Aroma': i[1], 'Appearance': i[2], 'Taste': i[3], 'Overall': i[4], 'User': i[5] } for i in beer.getReviews(i[0])] } for i in user.getUsers(0, 2): USERS[i[0]] = {'Username': i[1], 'Password': i[2]} for i in review.getReviews(0, 2): REVIEWS[i[0]] = { 'UID': i[1], 'Beer': i[2], 'Aroma': i[3], 'Appearance': i[4], 'Taste': i[5], 'Overall': i[6] } # Beer Classes class Beer(Resource): # REST methods
abort(404, message="User {} is not in the database".format(_id)) if sel == 3: if _id not in REVIEWS.keys(): abort(404, message="Review {} is not in the database".format(_id)) # Dict to hold all values (for formatting) BEER = {} USERS = {} REVIEWS = {} # Populate dicts above with db for i in beer.getBeers(0, 2): BEER[i[0]] = {'IBU': i[1], 'Calories': i[2], 'ABV': i[3], 'Brewery': i[4], 'Style': i[5], 'UID': i[6], 'Date': str(i[7]), 'Reviews': [{'Aroma': i[1], 'Appearance': i[2], 'Taste': i[3], 'Overall': i[4], 'User': i[5]} for i in beer.getReviews(i[0])]} for i in user.getUsers(0, 2): USERS[i[0]] = {'Username': i[1], 'Password': i[2]} for i in review.getReviews(0, 2): REVIEWS[i[0]] = {'UID': i[1], 'Beer': i[2], 'Aroma': i[3], 'Appearance': i[4], 'Taste': i[5], 'Overall': i[6]} # Beer Classes class Beer(Resource): # REST methods def get(self, beer_id): error(beer_id, 1) return BEER[beer_id] def delete(self, beer_id): error(beer_id, 1) beer.delBeer(beer_id)