本文整理汇总了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