from behance_python.behance import Behance from behance_python.user import User def remove_dot_key(obj): for key in obj.keys(): new_key = key.replace(".", "") if new_key != key: obj[new_key] = obj[key] del obj[key] return obj # set API key key = raw_input('Input your Behance API key: ') behance = API(key) # db connection localClient = pymongo.MongoClient('localhost', 27017) db = localClient.behance dbusers = db.users dbprojects = db.projects dbprojects.remove({}) # clear existing db collection visitedProjects = {} users = [] for user in dbusers.find(): users.append(user)
def setUp(self): self.api = API(API_KEY)
def test_exception(self): with self.assertRaises(NotFound): project = self.api.get_project(1234) with self.assertRaises(Forbidden): self.api = API('12345') projs = self.api.project_search('apple')
def test_exception(self): with self.assertRaises(NotFound): collection = self.api.get_collection('asdf1234') with self.assertRaises(Forbidden): self.api = API('12345') collections = self.api.collection_search('apple')
def test_exception(self): with self.assertRaises(NotFound): wip = self.api.get_wip('asdf1234') with self.assertRaises(Forbidden): self.api = API('12345') wips = self.api.wip_search('apple')
def test_exception(self): with self.assertRaises(NotFound): user = self.api.get_user('asdf1234') with self.assertRaises(Forbidden): self.api = API('12345') users = self.api.user_search('apple')
from flask import render_template from behance_python.api import API import json import urllib from werkzeug.routing import FloatConverter as BaseFloatConverter from flask_negotiate import consumes, produces app = Flask(__name__) app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.DEBUG) client = MongoClient('mongodb://*****:*****@app.route('/') def index(): #render_template('/static/index.html') return '<a href="/call">Click for tweets</a>' @app.route('/call/<data>', methods=['GET', 'POST']) @consumes('application/json', 'text/html') def fetchTweets(data): coords = data print coords print "yeah!"
import csv import time # 时间戳转换 def timeTrans(stamp): timeArray = time.localtime(stamp) transTime = time.strftime('%Y%m%d', timeArray) return transTime path = '../Behance/files' if not os.path.exists(path): os.makedirs(path) behance = API('mCfVlxzktvga8E0HPEDt1GjzS1943EFp') # # 任选一个项目打印存储 # project1 = behance.get_project(project_id='4889175') # print(project1) # # 存储文本格式 # f1 = open('../Behance/files/proj1.txt', 'w') # f1.write(str(project1)) # f1.close() # # 存储csv,使用get_project # csv1 = open('../Behance/files/proj1.csv', 'w+', newline='') # writer = csv.writer(csv1) # try: # writer.writerow(('projectID', 'name', 'publishedTime', 'field1', 'field2', 'field3', 'views', 'appreciations', # 'comments', 'owner', 'city', 'country'))