本文整理匯總了Python中model.event.Event.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Event.save方法的具體用法?Python Event.save怎麽用?Python Event.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類model.event.Event
的用法示例。
在下文中一共展示了Event.save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from model.event import Event [as 別名]
# 或者: from model.event.Event import save [as 別名]
def post(self):
args = event_parser.parse_args()
newEvent = Event(
tag = args.tag,
name = args.name,
description = args.description,
venue = Venue.query.get_by_name(args.venue["name"]),
time = args.time,
date = args.date,
image = args.image,
gests = map(lambda gest: gest["username"], args.gests),
requirement = map(lambda req: Requirement(name=req["name"],quantity=req["quantity"]), args.requirement),
capacity = args.capacity,
visibility = Visibility.query.get(args.visibility),
owner = currentUser()
)
newEvent.save()
log.info("Crea un Evento con: {'tag':'%s'}" % newEvent.tag)
return newEvent, 201
示例2: get_topnews
# 需要導入模塊: from model.event import Event [as 別名]
# 或者: from model.event.Event import save [as 別名]
def get_topnews(results=8):
URL = "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&ned=%s&topic=%s&rsz=%d"
editions = ("es_cl", "en_us")
topics = {"w": "Internacional", "h": "Titulares"}
i = 0
for edition in editions:
for topic in topics:
url = URL % (edition, topic, results)
print F, url
response = urllib2.urlopen(url)
data = response.read()
news = json.loads(data)
if news["responseStatus"] == 200:
for result in news["responseData"]["results"]:
data = {}
data["title"] = result["titleNoFormatting"]
data["locale"] = edition
data["date"] = result["publishedDate"]
data["url"] = result["url"]
data["type"] = "news"
data["id"] = md5(data["url"]).hexdigest()
data["content"] = ""
event = {}
event["title"] = data["title"]
event["locale"] = data["locale"]
event["description"] = result["content"]
event["date"] = data["date"]
e_id = event["id"] = md5("%s %s" % (repr(data["title"]), data["url"])).hexdigest()
print F, repr("Crawled news: %s" % data["title"])
e = Event(event)
e.save()
n = Page(data)
n.parent_id = e_id
n.save()
if result.has_key("relatedStories"):
for related in result["relatedStories"]:
data = {}
data["title"] = related["titleNoFormatting"]
data["locale"] = edition
data["date"] = related["publishedDate"]
data["url"] = related["url"]
data["id"] = md5(data["url"]).hexdigest()
data["type"] = "news"
data["content"] = ""
print F, repr("Related news: %s" % data["title"])
n = Page(data)
n.parent_id = e_id
n.save()
i += 1
else:
print F, news["responseDetails"]
print F, "total news collected: %d" % i