def nightly_task(): log.info("batch started") hub.threadingLocal = threading_local() hub.begin() last = BatchRecord.select(orderBy=BatchRecord.q.last_handled).reversed() if last.count(): last_rec = last[0] from_when = last_rec.last_handled else: from_when = datetime.date.today() last_handled = datetime.datetime.now() current = BatchRecord(first_handled=from_when, last_handled=last_handled) hub.commit() try: current.artists_updated = update_artists(queries_per_run) current.venues_updated = update_venues() cleanup_db() current.email_sent, current.artist_pings, current.venue_pings = send_email(from_when, last_handled) current.finished = datetime.datetime.now() hub.commit() except Exception, inst: import traceback hub.rollback() for admin in Group.by_group_name("admin").users: util.email( admin.email_address, "BandRadar <*****@*****.**>", "batch error", "Batch failed, Andy is on it!\n\n" + traceback.format_exc(), )
def lastfm_artist_update(artist): artist_info = lastfm.artist_info(artist.name) artist.img_url = artist_info["img_url"] artist.tags = artist_info["tags"] sims_objs = [] sims_names = artist_info["similars"] for artist_name in sims_names: try: sim_artist = Artist.byNameI(artist_name) except SQLObjectNotFound: # keep out too-short names if len(artist_name) < 3: continue try: sim_artist = Artist(name=artist_name, added_by=UserAcct.get(1)) except SQLObjectIntegrityError: print "trying to add '%s'" % artist_name hub.rollback() hub.begin() # Artists added this way are *not* approved. This keeps them from # also having sims generated (when they could be non-local bands # that we really don't care much about.) # If they have events approved, then of course they are, too. sims_objs.append(sim_artist) artist.similars = sims_objs
def save_item(self, **kw): cur_datetime = date.today() if kw["createtime"] == "": kw["createtime"] = cur_datetime hub.begin() if kw["new"]: item = BillingItem( ItemCode=kw["itemcode"], ItemDescription=kw["itemdescription"], ItemUnitCost=kw["itemunitcost"], ItemType=kw["itemtype"], ItemDiscountMaxAllowed=kw["itemdiscountmaxallowed"], ItemStatus=kw["itemstatus"], ModifyTime=cur_datetime, ModifyId="wesley", CreateTime=cur_datetime, CreateId="wesley", ) else: if kw["createtime"] == "": createtime = cur_time else: time_strct = time.strptime(keywords["createtime"], "%Y-%m-%d %H:%M:%S") createtime = datetime( time_strct.tm_year, time_strct.tm_mon, time_strct.tm_mday, time_strct.tm_hour, time_strct.tm_min, time_strct.tm_sec, ) item = BillingItem.get(kw["id"]) item.ItemDescription = kw["itemdescription"] item.ItemUnitCost = kw["itemunitcost"] item.ItemType = kw["itemtype"] item.ItemDiscountMaxAllowed = kw["itemdiscountmaxallowed"] item.ItemStatus = kw["itemstatus"] item.ModifyTime = cur_datetime item.ModifyId = "wesley" item.CreateTime = kw["createtime"] item.CreateId = kw["createid"] hub.commit() hub.end() turbogears.flash("Changes saved!") raise cherrypy.HTTPRedirect(turbogears.url("/billing/edit_item?id=" + str(item.id)))
def changepassword(self, namespace, oldpassword, newpassword, repeat): ns = Namespace.byName(namespace) if ns.password != oldpassword: msg = INCORRECT_PASSWORD_MSG elif newpassword != repeat: msg = "The new password didn't match it's repeat." else: hub.begin() ns.password = newpassword hub.commit() hub.end() msg = "Password changed!" turbogears.flash(msg) url = turbogears.url("/namespace", namespace=namespace, password=ns.password) raise cherrypy.HTTPRedirect(url)
def hourly_task(): hub.threadingLocal = threading_local() hub.begin() # notify admins of pending events added by users events_pending = Event.select(Event.q.approved == None) pending_count = events_pending.count() unnotified = events_pending.filter(Event.q.admin_notified == False) if unnotified.count(): for event in unnotified: event.admin_notified = True for admin in Group.by_group_name("admin").users: util.email( admin.email_address, "BandRadar <*****@*****.**>", "%d events in queue" % pending_count, "There are events in the pending queue.", ) hub.commit()