File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -233,6 +233,32 @@ def plotusers():
233233 updated = history .get ('updated' ),
234234 no_data = False )
235235
236+ @app .route ('/admin/update-user-count' )
237+ def update_user_count ():
238+ if not flask .request .headers .get ('X-Appengine-Cron' ):
239+ return flask .Response ('Forbidden' , status = 403 )
240+
241+ stat = ndb .Key ('__Stat_Kind__' , 'User' ).get ()
242+ count = stat .count if stat else 0
243+
244+ history_setting = ndb .Key ('Setting' , 'user_count_history' ).get ()
245+ if not history_setting :
246+ history_setting = Setting (id = 'user_count_history' )
247+ history = {'points' : []}
248+ elif history_setting .value == 'NOT SET' :
249+ history = {'points' : []}
250+ else :
251+ history = json .loads (history_setting .value )
252+
253+ now = datetime .utcnow ()
254+ history ['updated' ] = now .strftime ('%Y-%m-%d' )
255+ history ['points' ].append ({'month' : now .strftime ('%Y-%m' ), 'count' : count })
256+
257+ history_setting .value = json .dumps (history )
258+ history_setting .put ()
259+
260+ return flask .Response ('OK' , status = 200 )
261+
236262#
237263# Here are some utilities for validating names, hosts, and usernames
238264#
You can’t perform that action at this time.
0 commit comments