Exemplo n.º 1
0
class TestProject(BehanceTestCase):

    def test_search(self):
        projects = self.api.project_search('apple')
        self.assertEqual(len(projects), 12)
        for project in projects:
            for key in PROJECT_KEYS:
                self.assertTrue(project.has_key(key))
                self.assertTrue(hasattr(project, key))

    def test_project(self):
        project = self.api.get_project(PROJECT_ID)
        self.assertIsNotNone(project)
        for key in PROJECT_KEYS:
            self.assertTrue(hasattr(project, key))
            self.assertTrue(project.has_key(key))

    def test_comments(self):
        project = self.api.get_project(PROJECT_ID)
        comments = project.get_comments()
        self.assertGreater(len(comments), 1)
        for comment in comments:
            for key in ['user', 'comment']:
                self.assertTrue(comment.has_key(key))
                self.assertTrue(hasattr(comment, 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')
Exemplo n.º 2
0
class TestCollection(BehanceTestCase):
    def test_search(self):
        collections = self.api.collection_search('apple')
        self.assertGreaterEqual(len(collections), 1)
        for collection in collections:
            for key in COLLECTION_KEYS:
                self.assertTrue(collection.has_key(key))
                self.assertTrue(hasattr(collection, key))

    def test_collection(self):
        collection = self.api.get_collection(COLLECTION_ID)
        self.assertIsNotNone(collection)
        for key in COLLECTION_KEYS:
            self.assertTrue(hasattr(collection, key))
            self.assertTrue(collection.has_key(key))

    def test_collection_projects(self):
        collection = self.api.get_collection(COLLECTION_ID)
        projects = collection.get_projects()
        for project in projects:
            for key in PROJECT_KEYS:
                self.assertTrue(project.has_key(key))
                self.assertTrue(hasattr(project, key))

    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')
Exemplo n.º 3
0
class TestProject(BehanceTestCase):
    def test_search(self):
        projects = self.api.project_search('apple')
        self.assertEqual(len(projects), 12)
        for project in projects:
            for key in PROJECT_KEYS:
                self.assertTrue(project.has_key(key))
                self.assertTrue(hasattr(project, key))

    def test_project(self):
        project = self.api.get_project(PROJECT_ID)
        self.assertIsNotNone(project)
        for key in PROJECT_KEYS:
            self.assertTrue(hasattr(project, key))
            self.assertTrue(project.has_key(key))

    def test_comments(self):
        project = self.api.get_project(PROJECT_ID)
        comments = project.get_comments()
        self.assertGreater(len(comments), 1)
        for comment in comments:
            for key in ['user', 'comment']:
                self.assertTrue(comment.has_key(key))
                self.assertTrue(hasattr(comment, 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')
Exemplo n.º 4
0
class TestCollection(BehanceTestCase):
    
    def test_search(self):
        collections = self.api.collection_search('apple')
        self.assertGreaterEqual(len(collections), 1)
        for collection in collections:
            for key in COLLECTION_KEYS:
                self.assertTrue(collection.has_key(key))
                self.assertTrue(hasattr(collection, key))

    def test_collection(self):
        collection = self.api.get_collection(COLLECTION_ID)
        self.assertIsNotNone(collection)
        for key in COLLECTION_KEYS:
            self.assertTrue(hasattr(collection, key))
            self.assertTrue(collection.has_key(key))

    def test_collection_projects(self):
        collection = self.api.get_collection(COLLECTION_ID)
        projects = collection.get_projects()
        for project in projects:
            for key in PROJECT_KEYS:
                self.assertTrue(project.has_key(key))
                self.assertTrue(hasattr(project, key))

    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')
Exemplo n.º 5
0
class TestWIP(BehanceTestCase):

    def test_search(self):
        wips = self.api.wip_search('apple')
        self.assertEqual(len(wips), 12)
        for wip in wips:
            for key in WIP_KEYS:
                self.assertTrue(wip.has_key(key))
                self.assertTrue(hasattr(wip, key))

    def test_wip(self):
        wip = self.api.get_wip(WIP_ID)
        self.assertIsNotNone(wip)
        for key in WIP_KEYS:
            self.assertTrue(hasattr(wip, key))
            self.assertTrue(wip.has_key(key))

    def test_revision(self):
        wip = self.api.get_wip(WIP_ID)
        revision = wip.get_revision(WIP_REVISION_ID)
        for key in ['id', 'description', 'url']:
            self.assertTrue(revision.has_key(key))
            self.assertTrue(hasattr(revision, key))

    def test_comments(self):
        wip = self.api.get_wip(WIP_ID)
        comments = wip.get_revision_comments(WIP_REVISION_ID)
        for comment in comments:
            for key in ['user', 'comment', 'created_on']:
                self.assertTrue(comment.has_key(key))
                self.assertTrue(hasattr(comment, key))

    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')
Exemplo n.º 6
0
class TestWIP(BehanceTestCase):
    def test_search(self):
        wips = self.api.wip_search('apple')
        self.assertEqual(len(wips), 12)
        for wip in wips:
            for key in WIP_KEYS:
                self.assertTrue(wip.has_key(key))
                self.assertTrue(hasattr(wip, key))

    def test_wip(self):
        wip = self.api.get_wip(WIP_ID)
        self.assertIsNotNone(wip)
        for key in WIP_KEYS:
            self.assertTrue(hasattr(wip, key))
            self.assertTrue(wip.has_key(key))

    def test_revision(self):
        wip = self.api.get_wip(WIP_ID)
        revision = wip.get_revision(WIP_REVISION_ID)
        for key in ['id', 'description', 'url']:
            self.assertTrue(revision.has_key(key))
            self.assertTrue(hasattr(revision, key))

    def test_comments(self):
        wip = self.api.get_wip(WIP_ID)
        comments = wip.get_revision_comments(WIP_REVISION_ID)
        for comment in comments:
            for key in ['user', 'comment', 'created_on']:
                self.assertTrue(comment.has_key(key))
                self.assertTrue(hasattr(comment, key))

    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')
Exemplo n.º 7
0
 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')
Exemplo n.º 8
0
 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')
Exemplo n.º 9
0
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!"
Exemplo n.º 10
0
class TestUser(BehanceTestCase):
    def test_search(self):
        users = self.api.user_search('alex')
        self.assertEqual(len(users), 12)
        for user in users:
            for key in USER_KEYS:
                self.assertTrue(user.has_key(key))
                self.assertTrue(hasattr(user, key))

    def test_user(self):
        user = self.api.get_user(USER_NAME)
        self.assertIsNotNone(user)
        for key in USER_KEYS:
            self.assertTrue(hasattr(user, key))
            self.assertTrue(user.has_key(key))

    def test_user_projects(self):
        user = self.api.get_user(USER_NAME)
        projects = user.get_projects()
        self.assertIsNotNone(projects)
        for project in projects:
            for key in PROJECT_KEYS:
                self.assertTrue(project.has_key(key))
                self.assertTrue(hasattr(project, key))

    def test_user_wips(self):
        user = self.api.get_user(USER_NAME)
        wips = user.get_wips()
        self.assertIsNotNone(wips)
        for wip in wips:
            for key in WIP_KEYS:
                self.assertTrue(wip.has_key(key))
                self.assertTrue(hasattr(wip, key))

    def test_user_appreciations(self):
        user = self.api.get_user(USER_NAME)
        appreciations = user.get_appreciations()
        self.assertIsNotNone(appreciations)
        for appreciation in appreciations:
            for key in ['project', 'timestamp']:
                self.assertTrue(appreciation.has_key(key))
                self.assertTrue(hasattr(appreciation, key))

    def test_user_collections(self):
        user = self.api.get_user(USER_NAME)
        collections = user.get_collections()
        self.assertIsNotNone(collections)
        for collection in collections:
            for key in COLLECTION_KEYS:
                self.assertTrue(collection.has_key(key))
                self.assertTrue(hasattr(collection, key))

    def test_user_stats(self):
        user = self.api.get_user(USER_NAME)
        stats = user.get_stats()
        self.assertIsNotNone(stats)
        self.assertTrue(stats.has_key('today'))
        self.assertTrue(stats.has_key('all_time'))
        self.assertTrue(hasattr(stats, 'today'))
        self.assertTrue(hasattr(stats, 'all_time'))

    def test_user_followers(self):
        user = self.api.get_user(USER_NAME)
        followers = user.get_followers()
        self.assertIsNotNone(followers)
        for follower in followers:
            self.assertTrue(follower.has_key('id'))
            self.assertTrue(follower.has_key('username'))
            self.assertTrue(hasattr(follower, 'id'))
            self.assertTrue(hasattr(follower, 'username'))

    def test_user_following(self):
        user = self.api.get_user(USER_NAME)
        following = user.get_following()
        self.assertIsNotNone(following)
        for follow in following:
            self.assertTrue(follow.has_key('id'))
            self.assertTrue(follow.has_key('username'))
            self.assertTrue(hasattr(follow, 'id'))
            self.assertTrue(hasattr(follow, 'username'))

    def test_user_work_experience(self):
        user = self.api.get_user(USER_NAME)
        work_experience = user.get_work_experience()
        WE_KEYS = ['position', 'organization', 'location']
        for we in work_experience:
            for key in WE_KEYS:
                self.assertTrue(we.has_key(key))
                self.assertTrue(hasattr(we, key))

    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')
Exemplo n.º 11
0
 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')
Exemplo n.º 12
0
 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')
Exemplo n.º 13
0
 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')
Exemplo n.º 14
0
 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')
Exemplo n.º 15
0
 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')
Exemplo n.º 16
0
 def setUp(self):
     self.api = API(API_KEY)
Exemplo n.º 17
0
class TestUser(BehanceTestCase):

    def test_search(self):
        users = self.api.user_search('alex')
        self.assertEqual(len(users), 12)
        for user in users:
            for key in USER_KEYS:
                self.assertTrue(user.has_key(key))
                self.assertTrue(hasattr(user, key))

    def test_user(self):
        user = self.api.get_user(USER_NAME)
        self.assertIsNotNone(user)
        for key in USER_KEYS:
            self.assertTrue(hasattr(user, key))
            self.assertTrue(user.has_key(key))
    
    def test_user_projects(self):
        user = self.api.get_user(USER_NAME)
        projects = user.get_projects()
        self.assertIsNotNone(projects)
        for project in projects:
            for key in PROJECT_KEYS:
                self.assertTrue(project.has_key(key))
                self.assertTrue(hasattr(project, key))

    def test_user_wips(self):
        user = self.api.get_user(USER_NAME)
        wips = user.get_wips()
        self.assertIsNotNone(wips)
        for wip in wips:
            for key in WIP_KEYS:
                self.assertTrue(wip.has_key(key))
                self.assertTrue(hasattr(wip, key))

    def test_user_appreciations(self):
        user = self.api.get_user(USER_NAME)
        appreciations = user.get_appreciations()
        self.assertIsNotNone(appreciations)
        for appreciation in appreciations:
            for key in ['project', 'timestamp']:
                self.assertTrue(appreciation.has_key(key))
                self.assertTrue(hasattr(appreciation, key))

    def test_user_collections(self):
        user = self.api.get_user(USER_NAME)
        collections = user.get_collections()
        self.assertIsNotNone(collections)
        for collection in collections:
            for key in COLLECTION_KEYS:
                self.assertTrue(collection.has_key(key))
                self.assertTrue(hasattr(collection, key))

    def test_user_stats(self):
        user = self.api.get_user(USER_NAME)
        stats = user.get_stats()
        self.assertIsNotNone(stats)
        self.assertTrue(stats.has_key('today'))
        self.assertTrue(stats.has_key('all_time'))
        self.assertTrue(hasattr(stats, 'today'))
        self.assertTrue(hasattr(stats, 'all_time'))

    def test_user_followers(self):
        user = self.api.get_user(USER_NAME)
        followers = user.get_followers()
        self.assertIsNotNone(followers)
        for follower in followers:
            self.assertTrue(follower.has_key('id'))
            self.assertTrue(follower.has_key('username'))
            self.assertTrue(hasattr(follower, 'id'))
            self.assertTrue(hasattr(follower, 'username'))

    def test_user_following(self):
        user = self.api.get_user(USER_NAME)
        following = user.get_following()
        self.assertIsNotNone(following)
        for follow in following:
            self.assertTrue(follow.has_key('id'))
            self.assertTrue(follow.has_key('username'))
            self.assertTrue(hasattr(follow, 'id'))
            self.assertTrue(hasattr(follow, 'username'))

    def test_user_feedback(self):
        user = self.api.get_user(USER_NAME)
        feedback = user.get_feedback()
        KEYS = ['id', 'username', 'url']
        for fb in feedback:
            for key in KEYS:
                self.assertTrue(fb.has_key(key))
                self.assertTrue(hasattr(fb, key))

    def test_user_work_experience(self):
        user = self.api.get_user(USER_NAME)
        work_experience = user.get_work_experience()
        WE_KEYS = ['position', 'organization', 'location']
        for we in work_experience:
            for key in WE_KEYS:
                self.assertTrue(we.has_key(key))
                self.assertTrue(hasattr(we, key))

    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')
Exemplo n.º 18
0
 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')
Exemplo n.º 19
0
        new_key = key.replace(".","")
        if new_key != key:
            obj[new_key] = obj[key]
            del obj[key]
    return obj

# seed
random.seed("90948148")

# total users 1,500,000
max_users        = 50000
max_steps        = 1000 # graph cadinality n is not available

# set API key
key = raw_input('Input your Behance API key: ');
behance = API(key)

# db connection
db_client = pymongo.MongoClient('localhost', 27017)
db          = db_client.behance
seed_users   = []
for user in db.seed_users.find():
    user = user['user']
    num_links = user["stats"]["following"] + user["stats"]["followers"]
    if num_links>5:
        seed_users.append(user)

print "Size of Seed Pool: ", len(seed_users)

dbusers = db.users
dbusers.drop_indexes()
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
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'))