def Trending(request): if 'since' in request.GET: if request.META.has_key('HTTP_X_FORWARDED_FOR'): ip = request.META['HTTP_X_FORWARDED_FOR'] else: ip = request.META['REMOTE_ADDR'] i = IP(ip=ip) i.save() if not os.path.exists(settings.dirs): os.mkdir(settings.dirs) since = request.GET['since'] language = request.GET.get('language') if language is not None: language = urllib.quote(language) filename = util._get_time() + since + language + '.json' else: filename = util._get_time() + since + '.json' # 查找是否已经请求过 local_path = settings.dirs + '/' + filename if os.path.exists(local_path): with open(local_path, 'r') as file: content = file.readline() if content is not '': return HttpResponse(content) if language is not None: trending_api = settings.CODEHUB_API_LAN % (since, language) else: trending_api = settings.CODEHUB_API % since _trending_json = requests.get(trending_api) with open(local_path, 'w') as f: f.write(_trending_json.text.encode('utf-8')) return HttpResponse(_trending_json.text)
def GET(self): params = getInput(web.input()) github_url = params['github'] print github_url m2 = hashlib.md5() m2.update(github_url) url_md5 = m2.hexdigest() if os.path.exists(dirs + '/' + _get_time() + url_md5): with open(dirs + '/' + _get_time() + url_md5, 'r') as f: c = f.readline() # if not c == None: # return c _json = requests.get(github_url, verify=False) print _json.text if (_json): _json_data = json.loads(_json.text) for j in _json_data: print j n = j['name'].lower() print n if n == 'readme.md': github_url += j['path'] _json = requests.get(github_url, verify=False) break with open(dirs + '/' + _get_time() + url_md5, 'w') as f: f.write(_json.text.encode('utf-8')) return _json.text
def GET(self): if not os.path.exists(dirs): os.mkdir(dirs) print web.input() params = getInput(web.input()) print params since = params.get('since') language = params.get('language') if not language == None: language = urllib.quote(language) print language if not language == None: filename = _get_time() + since + language + '.json' else: filename = _get_time() + since + '.json' if os.path.exists(dirs + '/' + filename): with open(dirs + '/' + filename,'r') as f: content = f.readline() if not content == '': return content if not language == None: trending_api = CODEHUB_API_LAN % (since,language) else: trending_api = CODEHUB_API % since print trending_api _trending_json = requests.get(trending_api) with open('CodeJsonData/' + filename,'w') as f: f.write(_trending_json.text.encode('utf-8')) return _trending_json.text
def GithubRepo(request): if 'github' in request.GET: github_url = request.GET['github'] m2 = hashlib.md5() m2.update(github_url) url_md5 = m2.hexdigest() if 'received_events' not in github_url: if os.path.exists(settings.dirs + '/' + _get_time() + url_md5): with open(settings.dirs + '/' + _get_time() + url_md5, 'r') as f: c = f.readline() if c is not None: return HttpResponse(c) _json = requests.get(github_url, verify=False, headers=settings.header) if 'README.md' in github_url: github_url = github_url.replace('README.md', '') _json = requests.get(github_url, verify=False) print _json.text if (_json): _json_data = json.loads(_json.text) for j in _json_data: print j n = j['name'].split('.')[0].lower() print n if n == 'readme': github_url += j['path'] _json = requests.get(github_url, verify=False) break with open(settings.dirs + '/' + _get_time() + url_md5, 'w') as f: f.write(_json.text.encode('utf-8')) return HttpResponse(_json.text)
def GET(self): print web.input() params = util.getInput(web.input()) q = params['q'] if not os.path.exists(search): os.mkdir(search) with open(search + '/q.txt', 'a') as f: f.write(_get_time() + '----' + q + '\n') q = urllib.quote(str(q)) print q api = SEARCH_API % q print api, header r = requests.get(api, verify=False, headers=header) return r.text
def faculty_profile(faculty_id): if request.method == 'GET': faculty = Faculty.query.filter_by(id=faculty_id).first() if faculty.user.minit is None: faculty.user.minit = '' faculty_result = [] faculty_dict = faculty.to_json_format() user_dict = faculty.user.to_json_format() json = util._merge_two_dicts(user_dict, faculty_dict) img_name = faculty.user.image.image_name img_ext = faculty.user.image.image_extension image_source = "/static/images/faculty/" + img_name + "." + img_ext json = util._append_to_dict(json, image_source, 'img_src') educations = faculty.educations edu_list = [e.to_json_format() for e in educations] json = util._append_to_dict(json, edu_list, 'educations') faculty_services = faculty.faculty_services service_list = [service.name for service in faculty_services] json = util._append_to_dict(json, service_list, 'services') faculty_interests = faculty.faculty_interests interest_list = [interest.interest for interest in faculty_interests] json = util._append_to_dict(json, interest_list, 'interests') faculty_committee_members = faculty.committee_members department_committee = [] college_committee = [] university_committee = [] inter_department_committee = [] professional_committee = [] for member in faculty_committee_members: committee = member.committee if committee.category == 'department': department_committee.append(committee.name) elif committee.category == 'college': college_committee.append(committee.name) elif committee.category == 'university': university_committee.append(committee.name) elif committee.category == 'professional': professional_committee.append(committee.name) else: inter_department_committee.append(committee.name) json = util._append_to_dict(json, department_committee, 'department_committee') json = util._append_to_dict(json, college_committee, 'college_committee') json = util._append_to_dict(json, university_committee, 'university_committee') json = util._append_to_dict(json, inter_department_committee, 'inter_department_committee') json = util._append_to_dict(json, professional_committee, 'professional_committee') officeHours = OfficeHours.query.filter_by(user_id=faculty.user_id) hours = [ util._get_time(h.start_time) + "-" + util._get_time(h.start_time) + " " + h.days for h in officeHours ] json = util._append_to_dict(json, hours, 'office_hours') json = util._append_to_dict(json, True, "isFaculty") faculty_result.append(json) return render_template("about/profile.html", data=faculty_result[0])
def faculty_profile(faculty_id): if request.method == 'GET': faculty = Faculty.query.filter_by(id=faculty_id).first() if faculty.user.minit is None: faculty.user.minit = '' faculty_result = [] faculty_dict = faculty.to_json_format() user_dict = faculty.user.to_json_format() json = util._merge_two_dicts(user_dict, faculty_dict) img_name = faculty.user.image.image_name img_ext = faculty.user.image.image_extension image_source = "/static/images/faculty/" + img_name + "." + img_ext json = util._append_to_dict(json, image_source, 'img_src') educations = faculty.educations edu_list = [e.to_json_format() for e in educations] json = util._append_to_dict(json, edu_list, 'educations') faculty_services = faculty.faculty_services service_list = [service.name for service in faculty_services] json = util._append_to_dict(json, service_list, 'services') faculty_interests = faculty.faculty_interests interest_list = [interest.interest for interest in faculty_interests] json = util._append_to_dict(json, interest_list, 'interests') faculty_committee_members = faculty.committee_members department_committee = [] college_committee = [] university_committee = [] inter_department_committee = [] professional_committee = [] for member in faculty_committee_members: committee = member.committee if committee.category == 'department': department_committee.append(committee.name) elif committee.category == 'college': college_committee.append(committee.name) elif committee.category == 'university': university_committee.append(committee.name) elif committee.category == 'professional': professional_committee.append(committee.name) else: inter_department_committee.append(committee.name) json = util._append_to_dict(json, department_committee, 'department_committee') json = util._append_to_dict(json, college_committee, 'college_committee') json = util._append_to_dict(json, university_committee, 'university_committee') json = util._append_to_dict(json, inter_department_committee, 'inter_department_committee') json = util._append_to_dict(json, professional_committee, 'professional_committee') officeHours = OfficeHours.query.filter_by(user_id=faculty.user_id) hours = [util._get_time(h.start_time) + "-" + util._get_time(h.start_time) + " " + h.days for h in officeHours] json = util._append_to_dict(json, hours, 'office_hours') json = util._append_to_dict(json, True, "isFaculty") faculty_result.append(json) return render_template("about/profile.html", data=faculty_result[0])