本文整理汇总了Python中parse_rest.datatypes.Object.factory方法的典型用法代码示例。如果您正苦于以下问题:Python Object.factory方法的具体用法?Python Object.factory怎么用?Python Object.factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parse_rest.datatypes.Object
的用法示例。
在下文中一共展示了Object.factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def run():
while True:
try:
citations = Object.factory("citations")
violations = Object.factory("violations")
users = Object.factory("user")
# violations = Object.factory("violations")
tomorrow_datetime = datetime.date.today() + datetime.timedelta(days=1)
tomorrow = '{dt.month}/{dt.day}/{dt.year} 0:00:00'.format(dt = tomorrow_datetime)
tomorrows_citations = citations.Query.filter(court_date=tomorrow,proactive_outreach=False)
for citation in tomorrows_citations:
try:
user = users.Query.get(first_name=citation.first_name,last_name=citation.last_name,birthdate=citation.date_of_birth)
reachout_sms = "Hey! It's a reminder from ProactiveLaw that you have a court date tomorrow in " + citation.court_location + " at " + citation.court_address + " to get more information call them at " + court_numbers[citation.court_location]
message = client.messages.create(body=reachout_sms,
to=user.phone_number, # Replace with your phone number
from_="+13142549337") # Replace with your Twilio number
# print message.sid
citation.proactive_outreach = True;
citation.save()
except:
print "No court date or not enough information"
warrant_violations = violations.Query.filter(status="FTA WARRANT ISSUED",proactive_outreach=False)
for violation in warrant_violations:
try:
citation = citations.Query.get(citation_number=violation.citation_number)
user = users.Query.get(first_name=citation.first_name,last_name=citation.last_name,birthdate=citation.date_of_birth)
amount_owed = violation.fine_amount + violation.court_cost
reachout_sms = "Hey! It's a notification from ProactiveLaw that a warrant " + violation.warrant_number + " has been issued for your arrest for violation: " + violation.violation_number + " " + violation.violation_description + ", you owe $" + str(amount_owed) + " to the court " + citation.court_location + " at " + citation.court_address + " to get more information call them at " + court_numbers[citation.court_location] + ". To Pay now respond with PAY " + violation.violation_number
message = client.messages.create(body=reachout_sms,
to=user.phone_number, # Replace with your phone number
from_="+13142549337") # Replace with your Twilio number
violation.proactive_outreach = True;
violation.save()
except:
print "No court date or not enough information"
payment_violations = violations.Query.filter(status="CONT FOR PAYMENT",proactive_outreach=False)
for violation in payment_violations:
try:
citation = citations.Query.get(citation_number=violation.citation_number)
user = users.Query.get(first_name=citation.first_name,last_name=citation.last_name,birthdate=citation.date_of_birth)
amount_owed = violation.fine_amount + violation.court_cost
reachout_sms = "Hey! It's a notification from ProactiveLaw that a payment is owed for violation: " + violation.violation_number + " " + violation.violation_description + ", you owe $" + str(amount_owed) + " to the court " + citation.court_location + " at " + citation.court_address + " to get more information call them at " + court_numbers[citation.court_location] + ". To Pay now respond with PAY " + violation.violation_number
message = client.messages.create(body=reachout_sms,
to=user.phone_number, # Replace with your phone number
from_="+13142549337") # Replace with your Twilio number
violation.proactive_outreach = True;
violation.save()
except:
print "No court date or not enough information"
# sys.exit(0)
except:
print "error"
time.sleep(5)
示例2: findTest
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def findTest():
global testIDs, testIDsNames
testNames = []
testIDs = []
testNameIDs = {}
testIDsNames = {}
myClassName = 'Tests'
myClass = Object.factory(myClassName)
word= myClass.Query.all()
splitword = str(word).split(':')
length = len(splitword)
for k in range (1,length-1):
line = splitword[k]
splitword[k] = line[:-9]
testIDs.append(splitword[k])
testIDs.append(splitword[length-1][:-2])
length = len(testIDs)
for k in range (0, length - 1):
name = myClass.Query.get(objectId = testIDs[k])
testNames.append(name.name)
name = myClass.Query.get(objectId = testIDs[length-1])
testNames.append(name.name)
for k in range (0, length):
testNameIDs[testNames[k]] = testIDs[k]
for k in range (0, length):
testIDsNames[testIDs[k]] = testNames[k]
print('FUNCTION: findTest COMPLETE')
print(time.asctime( time.localtime(time.time()) ))
return testIDs, testNames, testNameIDs
示例3: pupilResultsToTeacher
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def pupilResultsToTeacher(sameGroupID):
global resultIDs, testIDsNames, userDetails, userIDtoName, results, pupilUserName
results = []
value = str(classPupilsList.curselection())
strip = value.strip(',')
value = int(strip[1])
pupilID = sameGroupID[value]
pupilName = userIDtoName[pupilID]
pupilUserName = pupilName
myClassName = 'Results'
myClass = Object.factory(myClassName)
length = len(resultIDs)
for k in range(1, length):
obj = myClass.Query.get(objectId = resultIDs[k])
user = obj.userName
if user == pupilName:
testID = obj.testID
average = obj.average
average = '%.1f' % average
attempts = obj.attempts
testName = testIDsNames[testID]
string = (str(testName)+': Average = '+str(average)+'; Attempts = '+str(attempts))
results.append(string)
print('Results collected')
print(results)
pupilResultsList.delete(0, END)
length = len(results)
for k in range(0, length):
pupilResultsList.insert(k+1, results[k])
示例4: userIDsAndNames
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def userIDsAndNames():
global userIDtoName, userIDs, userDetails
names = []
userIDs = []
userDetails = {}
userIDtoName = {}
myClassName = 'User'
myClass = Object.factory(myClassName)
details = myClass.Query.all()
splitword = str(details).split(':')
length = len(splitword)
for k in range (1,length-1):
line = splitword[k]
names.append(line[:-24])
lastLine = str(splitword[length-1])[:-18]
names.append(lastLine)
splitword = str(details).split('Id ')
length = len(splitword)
for k in range (1,length-1):
line = splitword[k].split(')>,')
userIDs.append(line[0])
lastLine = str(splitword[length-1])[:-3]
userIDs.append(lastLine)
length = len(userIDs)
for k in range(0,length):
userDetails[names[k]] = userIDs[k]
userIDtoName[userIDs[k]] = names[k]
print('FUNCTION: userIDsAndNames COMPLETE')
print(time.asctime( time.localtime(time.time()) ))
return userDetails, names, userIDs
示例5: getSinglePost
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def getSinglePost(objectId):
settings_local.initParse()
className="Posts"
Posts=Object.factory(className)
SinglePost=Posts.Query.get(objectId=objectId)
print SinglePost.Image1.url
return SinglePost
示例6: outputUserResults
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def outputUserResults():
global username, resultIDs, testIDsNames
myClassName = 'Results'
myClass = Object.factory(myClassName)
results = []
length = len(resultIDs)
for k in range(1, length):
obj = myClass.Query.get(objectId = resultIDs[k])
user = obj.userName
if user == username:
testID = obj.testID
average = obj.average
average = '%.1f' % average
attempts = obj.attempts
testName = testIDsNames[testID]
string = (str(testName)+': Average = '+str(average)+'; Attempts = '+str(attempts))
results.append(string)
print('Results collected')
resultsList.delete(0, END)
length = len(results)
for k in range(0, length):
resultsList.insert(k+1, results[k])
length = len(results)
resultsList.config(height = length)
print('FUNCTION outputUserResults COMPLETE')
print(time.asctime( time.localtime(time.time()) ))
示例7: Login
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def Login(userIDClass):
global username, userDetails
username = usernameEntry.get()
password = passwordEntry.get()
myClassName = 'User'
myClass = Object.factory(myClassName)
username = str(username.lower())
Id = userDetails[username]
print(Id)
data = myClass.Query.get(objectId = Id)
teacher = data.teacher
print(teacher)
if username in userDetails:
print('Logging in')
try:
User.login(username, password)
print('Logged in')
currentUserLabel.config(text = 'Logged in as '+username+'. Class: '+userIDClass[Id])
if teacher == False:
outputUserResults()
newWordButton.config(state = DISABLED)
quizSelectButton.config(state = NORMAL)
else:
newWordButton.config(state = NORMAL)
quizSelectButton.config(state = DISABLED)
resultsList.delete(0, END)
findTeachersPupils(Id)
except:
print('Incorrect password')
currentUserLabel.config(text = 'Incorrect password')
else:
currentUserLabel.config(text = 'That is an invalid username')
print('That is an invalid username')
print('FUNCTION: userLogin COMPLETE')
print(time.asctime( time.localtime(time.time()) ))
示例8: main
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def main():
soup = BeautifulSoup(requests.get('https://www.mturk.com/mturk/viewhits?searchWords=&pageNumber=4&searchSpec=HITGroupSearch%23T%231%2310%23-1%23T%23%21%23%21NumHITs%211%21%23%21&sortType=NumHITs%3A1&selectedSearchType=hitgroups').text, "html.parser")
titles = soup.findAll('a', {"class" : "capsulelink"})
num_results = int(soup.findAll('td', {"class" : "title_orange_text"})[0].text.strip()[8:-7])
print("\nTotal number of HITs: " + str(num_results))
count = 0
page = 1
requestErrors = 0
privateCount = 0
register("DKJjvfvhnCGRK0cAdOpJN9MwR7zhIpuYya5xvbuF", "d8hIYrBrcW4r2ujEkL79vE03FmLxE2QCJgSwuXYv")
HITClass = ParseObject.factory("HIT")
all_hits = HITClass.Query.all()
batcher = ParseBatcher()
batcher.batch_delete(all_hits)
while (count < 200):
soup = BeautifulSoup(requests.get('https://www.mturk.com/mturk/viewhits?searchWords=&pageNumber=' + str(page) + '&searchSpec=HITGroupSearch%23T%231%2310%23-1%23T%23%21%23%21NumHITs%211%21%23%21&sortType=NumHITs%3A1&selectedSearchType=hitgroups').text, "html.parser")
titles = soup.findAll('a', {"class" : "capsulelink"})
for t in titles:
time.sleep(.3)
count = count + 1
print("\n" + str(count) + "\nTitle: " + t.text.strip())
linkA = t.parent.parent.findAll('span')[1].a
# check if the link is public
if linkA.has_attr('href'):
link = linkA['href']
hitPage = BeautifulSoup(requests.get('https://www.mturk.com' + link).text, "html.parser")
form = hitPage.findAll('form', {'name' : 'hitForm'})
# Check for error
if len(form) >= 3:
form = form[2]
requester = form.find("input", {'name' : 'prevRequester'})['value']
print('Requester: ' + requester)
reward = form.find("input", {'name' : 'prevReward'})['value']
print('Reward: ' + reward)
groupID = form.find("input", {'name' : 'groupId'})['value']
print('Group id: ' + groupID)
anyObject = HIT(requester=requester, reward=float(reward[3:]),
title=t.text.strip(), groupID=groupID)
anyObject.save()
else:
requestErrors = requestErrors + 1
print(link)
print(form)
else:
link = linkA['id']
print(link)
privateCount = privateCount + 1
page = page + 1
print("\n\nErrors: " + str(requestErrors))
print("Private HITs: " + str(privateCount))
示例9: create_event_users_in_Parse
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def create_event_users_in_Parse(self):
# For now, just grab first ones; later, check by array_eventsRegistered.
"""
Create zE0000_User objects by "batch_save"-ing them to Parse using
ParsePy's ParseBatcher(). Event User objects are _User objects whose
array_eventsRegistered contains the eventNum of this current event.
"""
eu_ClassName = "zE" + _Event.STR_EVENT_SERIAL_NUM + "_User"
eu_Class = Object.factory(eu_ClassName)
# # Get the correct class name from the ep = Event Prefix (passed in).
# eventUser_ClassName = ep + "_User"
# eventUser_Class = Object.factory(eventUser_ClassName)
# add some Users to this Event
qset_all_users = User.Query.all().order_by("userNum")
li_meu = list(qset_all_users.filter(sex = "M").limit(
_Event.MEN))
li_feu = list(qset_all_users.filter(sex = "F").limit(
_Event.WOMEN))
li_mgeu = list(qset_all_users.filter(sex = "MG").limit(
self.num_m_ghosts))
li_fgeu = list(qset_all_users.filter(sex = "FG").limit(
self.num_f_ghosts))
li_users_at_event = li_meu + li_feu + li_mgeu + li_fgeu
count_eu = len(li_users_at_event)
li_eu_obj_to_upload = []
for index, obj_User in enumerate(li_users_at_event):
new_EU_object = eu_Class(
user_objectId = obj_User.objectId,
event_userNum = index + 1,
username = obj_User.username,
first = obj_User.username.split(" ")[0],
last = obj_User.username.split(" ")[-1],
sex = obj_User.sex
)
li_eu_obj_to_upload.append(new_EU_object)
# Batch upload in chunks no larger than 50,
# and sleep to avoid timeouts
batch_upload_to_Parse(eu_ClassName, li_eu_obj_to_upload)
pass
示例10: __init__
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def __init__(self, options, columns):
super(ParseFdw, self).__init__(options, columns)
self.columns = columns
try:
self.application_id = options['application_id']
self.rest_api_key = options['rest_api_key']
self.className = options['class_name']
except KeyError:
log_to_postgres("You must specify an application_id, rest_api_key and class_name options when creating this FDW.", ERROR)
register(self.application_id, self.rest_api_key)
self.object = Object.factory(self.className)
示例11: getResultIDs
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def getResultIDs():
global resultIDs
resultIDs =[]
myClassName = 'Results'
myClass = Object.factory(myClassName)
returned = str(myClass.Query.all())
splited = returned.split('Results:')
length = len(splited)
for k in range(0, length-1):
resultIDs.append(splited[k][:-4])
resultIDs.append(splited[length - 1][:-2])
print('FUNCTION getRestultIDs COMPLETE')
print(time.asctime( time.localtime(time.time()) ))
示例12: getWordDetails
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def getWordDetails():
global IDsandDefinitions
wordIDs = []
words = []
nameIDs = {}
IDsandTest = {}
IDsandDefinitions = {}
myClassName = 'Words'
myClass = Object.factory(myClassName)
word = myClass.Query.all()
splitword = str(word).split(':')
length = len(splitword)
for k in range (1,length-1):
line = splitword[k]
splitword[k] = line[:-9]
wordIDs.append(splitword[k])
print('wordIDs FOUND')
print(time.asctime( time.localtime(time.time()) ))
wordIDs.append(splitword[length-1][:-2])
length = len(wordIDs)
for k in range(0, length):
word = myClass.Query.get(objectId = wordIDs[k])
words.append(word.text)
print('words FOUND')
print(time.asctime( time.localtime(time.time()) ))
for k in range(0, length - 1):
nameIDs[wordIDs[k]] = words[k]
print('words and wordIDs ASSIGNED')
print(time.asctime( time.localtime(time.time()) ))
nameIDs[wordIDs[length-1]] = words[length-1]
for k in range(0, length - 1):
testID = myClass.Query.get(objectId = wordIDs[k])
testID = testID.testID
IDsandTest[wordIDs[k]] = testID
print('testID and wordIDs ASSIGNED')
print(time.asctime( time.localtime(time.time()) ))
testID = myClass.Query.get(objectId = wordIDs[length-1])
testID = testID.testID
IDsandTest[wordIDs[length-1]] = testID[:-2]
for k in range(0, length - 1):
definition = myClass.Query.get(objectId = wordIDs[k])
definition = definition.definition
IDsandDefinitions[wordIDs[k]] = definition
definition = myClass.Query.get(objectId = wordIDs[length-1])
definition = definition.definition
print('wordIDs and Definitions ASSIGNED')
print(time.asctime( time.localtime(time.time()) ))
IDsandDefinitions[wordIDs[length-1]] = definition[:-2]
print('FUNCTION: getWordDetails COMPLETE')
print(time.asctime( time.localtime(time.time()) ))
return wordIDs, words, nameIDs, IDsandTest, IDsandDefinitions
示例13: historyToTeacher
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def historyToTeacher():
global results, testNameIDs, pupilUserName
user = pupilUserName
historyIDs = []
outputList = []
value = str(pupilResultsList.curselection())
strip = value.strip(',')
value = int(strip[1])
line = results[value]
strip = line.split(': Average')
testname = strip[0]
testID = testNameIDs[testname]
myClassName = 'History'
myClass = Object.factory(myClassName)
output = myClass.Query.all()
print(output)
length = len(output)
print(length)
for k in range(0, length):
strip = str(output[k]).strip('<>')
split = strip.split(':')
historyIDs.append(split[1])
print(split[1])
for k in range(0, length):
result = myClass.Query.get(objectId = historyIDs[k])
historyUsername = result.userName
historyTestID = result.testID
if historyUsername == pupilUserName and historyTestID == testID:
date = result.createdAt
date = str(date)[:10]
score = result.score
string = (str(date)+': scored '+str(score))
outputList.append(string)
else:
pass
historyList.delete(0, END)
length = len(outputList)
for k in range(0, length):
historyList.insert(k+1, outputList[k])
示例14: classDetails
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def classDetails(userIDs):
global userIDClass
classNames = []
userIDClass = {}
ClassUseriD = {}
length = len(userIDs)
myClassName = 'User'
myClass = Object.factory(myClassName)
for k in range(0, length):
Id = userIDs[k]
data = myClass.Query.get(objectId = Id)
group = data.group
userIDClass[Id] = group
if group in classNames:
pass
else:
classNames.append(group)
return classNames, userIDClass
示例15: updateResults
# 需要导入模块: from parse_rest.datatypes import Object [as 别名]
# 或者: from parse_rest.datatypes.Object import factory [as 别名]
def updateResults():
global resultIDs, username, score, testID
length = len(resultIDs)
run = 1
myClassName = 'Results'
myClass = Object.factory(myClassName)
while run == 1:
for k in range(1,length):
obj = myClass.Query.get(objectId = resultIDs[k])
user = obj.userName
test = obj.testID
if user == username and test == testID:
attempts = obj.attempts
average = obj.average
total = attempts*average
attempts = attempts + 1
average = (total + score)/attempts
print('Attempts:'+str(attempts),'Average:'+str(average))
obj.average = average
obj.attempts = attempts
obj.save()
print('Saved')
run = 0