forked from avh4/khan-academy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevpanel.py
143 lines (100 loc) · 5.27 KB
/
devpanel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import os, logging
from google.appengine.ext import db
from google.appengine.api import users
import util
from app import App
from models import UserData
import request_handler
import user_util
import itertools
from api.auth.xsrf import ensure_xsrf_cookie
import gdata.youtube
import gdata.youtube.data
import gdata.youtube.service
import urllib
import csv
class Email(request_handler.RequestHandler):
@user_util.developer_only
@ensure_xsrf_cookie
def get(self):
current_email = self.request.get('curremail') #email that is currently used
new_email = self.request.get('newemail') #email the user wants to change to
swap = self.request.get('swap') #Are we changing emails?
currdata = UserData.get_from_user_input_email(current_email)
newdata = UserData.get_from_user_input_email(new_email)
if swap and currdata: #are we swapping? make sure account exists
currdata.current_user = users.User(new_email)
currdata.user_email = new_email
if newdata: #delete old account
currdata.user_id = newdata.user_id
newdata.delete()
currdata.put()
template_values = {'App' : App, 'curremail': current_email, 'newemail': new_email, 'currdata': currdata, 'newdata': newdata, "properties": UserData.properties()}
self.render_jinja2_template('devemailpanel.html', template_values)
class Manage(request_handler.RequestHandler):
@user_util.admin_only # only admins may add devs, devs cannot add devs
@ensure_xsrf_cookie
def get(self):
developers = UserData.all()
developers.filter('developer = ', True).fetch(1000)
template_values = { "developers": developers }
self.render_jinja2_template('managedevs.html', template_values)
class ManageCoworkers(request_handler.RequestHandler):
@user_util.developer_only
@ensure_xsrf_cookie
def get(self):
user_data_coach = self.request_user_data("coach_email")
user_data_coworkers = []
if user_data_coach:
user_data_coworkers = user_data_coach.get_coworkers_data()
template_values = {
"user_data_coach": user_data_coach,
"user_data_coworkers": user_data_coworkers
}
self.render_jinja2_template("managecoworkers.html", template_values)
class CommonCore(request_handler.RequestHandler):
@user_util.developer_only
def get(self):
cc_videos = []
cc_file = "common_core/"
auth_sub_url = ""
token = self.request_string("token")
if token: # AuthSub token from YouTube API - load and tag videos
# default for yt_user is test account khanacademyschools
yt_account = self.request_string("account") if self.request_string("account") else "khanacademyschools"
logging.info("****Youtube Account: " + yt_account)
cc_file += "cc_video_mapping.csv" if yt_account == "khanacademy" else "test_data.csv"
yt_service = gdata.youtube.service.YouTubeService()
yt_service.SetAuthSubToken(token)
yt_service.UpgradeToSessionToken()
yt_service.developer_key = 'AI39si6eFsAasPBlI_xQLee6-Ii70lrEhGAXn_ryCSWQdMP8xW67wkawIjDYI_XieWc0FsdsH5HMPPpvenAtaEl5fCLmHX8A5w'
f = open(cc_file, 'U')
reader = csv.DictReader(f, dialect='excel')
for record in reader:
if not record["youtube_id"] == "#N/A":
entry = yt_service.GetYouTubeVideoEntry(video_id=record["youtube_id"])
if entry and record["keyword"] not in entry.media.keywords.text:
keywords = entry.media.keywords.text or ""
entry.media.keywords.text = keywords + "," + record["keyword"]
video_url = "https://gdata.youtube.com/feeds/api/users/"+ yt_account + "/uploads/" + record["youtube_id"]
updated_entry = yt_service.UpdateVideoEntry(entry, video_url)
logging.info("***PROCESSED*** Title: " + entry.media.title.text)
if not updated_entry:
logging.warning("***FAILED update*** Title: " + record["title"] + ", ID: " + record["youtube_id"])
cc_videos.append(record)
f.close()
else:
params = {
'next': self.request.url,
'scope': "http://gdata.youtube.com",
'session': "1",
'secure': "0"
}
base_url = "https://www.google.com/accounts/AuthSubRequest?"
auth_sub_url = base_url + urllib.urlencode(params)
template_values = {
"token" : token,
"cc_videos" : cc_videos,
"auth_sub_url" : auth_sub_url
}
self.render_jinja2_template("commoncore.html", template_values)