Пример #1
0
def test_graph_update():
    api.login("system", os.getenv("SYSTEM_PWD"))

    data = {
        'name': "bob",
        'age': 39,
    }

    resp = api.post('/api/data/user', data)

    id = resp['uid']
    user_url = '/api/data/user/{0}'.format(id)

    nquads = '\n'.join(['<{0}> <first_lang> "ru" .'.format(id)])
    api.post('/api/nquads', nquads, content_type='application/n-quads')

    resp = api.get(user_url)
    assert resp['first_lang'] == 'ru'

    mutation = {
        'set': '\n'.join(['<{0}> <age> "38"^^<xs:int> .'.format(id)]),
        'delete': '\n'.join(['<{0}> <first_lang> * .'.format(id)]),
    }
    api.post('/api/nquads', mutation)

    resp = api.get(user_url)
    assert resp['age'] == 38
    assert 'first_lang' not in resp

    api.delete(user_url)
Пример #2
0
def follow(db, user, leader_id):
    # only follow someone if this user hasn't already followed them,
    # and hasn't followed anyone too recently,
    # and hasn't followed too many people recently:
    with db, db.cursor() as cursor:
        twitter = database.get_twitter(cursor, leader_id)
        user_follow = database.get_user_follow(cursor, user.id, leader_id)
        last_follow_time = database.get_user_follows_last_time(cursor, user.id)
        follows_today = database.get_user_follows_count(cursor, user.id, now() - DAY)
    log(user, 'following %s last followed at %s and %d follows today',
        twitter.api_id, last_follow_time, follows_today)
    if user_follow:
        return warn(user, 'but they were already followed at %s', user_follow.time)
    if last_follow_time and last_follow_time > now() - FOLLOW_PERIOD:
        return warn(user, 'but followed too recently')
    if follows_today >= MAX_FOLLOWS_PER_DAY:
        return warn(user, 'but too many follows today')

    try:
        api.post(user, 'friendships/create', user_id=twitter.api_id)
        followed = True
    except requests.exceptions.HTTPError as e:
        if e.response.status_code != 403:
            raise e
        # 403 can mean blocked or already following, so we mark as followed
        warn(user, 'marking %s as followed [%d %s]',
             twitter.api_id, e.response.status_code, e.response.text)
        followed = False

    with db, db.cursor() as cursor:
        database.add_user_follow(cursor, user.id, leader_id)
        if followed:
            database.update_twitter_followers(cursor, leader_id, [user.twitter_id])
Пример #3
0
def unfollow(db, user, leader_id):
    # only unfollow someone if this user followed them,
    # and they've had some time to follow them back but didn't:
    with db, db.cursor() as cursor:
        twitter = database.get_twitter(cursor, leader_id)
        user_follow = database.get_user_follow(cursor, user.id, leader_id)
        user_unfollow = database.get_user_unfollow(cursor, user.id, leader_id)
        follower = database.get_twitter_follower(cursor, user.twitter_id, leader_id)
    log(user, 'unfollowing %s followed at %s',
        twitter.api_id, user_follow.time if user_follow else None)
    if not user_follow:
        return warn(user, 'but they were never followed')
    if user_unfollow:
        return warn(user, 'but they were already unfollowed at %s', user_unfollow.time)
    if user_follow.time > now() - UNFOLLOW_LEADERS_PERIOD:
        return warn(user, 'but they were followed too recently')
    if follower and user_follow.time > now() - UNFOLLOW_FOLLOWERS_PERIOD:
        return warn(user, 'but they were followed too recently for someone who followed back')

    try:
        api.post(user, 'friendships/destroy', user_id=twitter.api_id)
    except requests.exceptions.HTTPError as e:
        if e.response.status_code != 404:
            raise e
        return warn(user, 'failed to unfollow %s [%d %s]',
                    twitter.api_id, e.response.status_code, e.response.text)

    with db, db.cursor() as cursor:
        database.add_user_unfollow(cursor, user.id, leader_id)
        database.delete_twitter_follower(cursor, leader_id, user.twitter_id)
Пример #4
0
    def test_person_insert(self):
        '''
        Testa cadastrar uma pessoa.
        '''
        url = '/person/'
        api = webtest.TestApp(self.base_url)
        try:
            error = ''
            r = api.post(url, {'facebookId': 'bla^bla'})
        except webtest.AppError as e:
            error = e.message
        self.assertTrue(error.find('404') > -1)

        try:
            error = ''
            r = api.post(url, {'facebookId': 'bla/bla'})
        except webtest.AppError as e:
            error = e.message
        self.assertTrue(error.find('400') > -1)

        #testa o insert
        r = api.post(url, {'facebookId': 100000429486498})
        self.assertEqual(r.status_int, 201)
        contents = r.json
        self.assertTrue('created' in contents)
        self.assertTrue(contents['created'])

        #testa o update
        r = api.post(url, {'facebookId': 100000429486498})
        self.assertEqual(r.status_int, 200)
        contents = r.json
        self.assertTrue('created' in contents)
        self.assertFalse(contents['created'])
Пример #5
0
def post_if_not_exist(resource, obj, w):
    r = api.get(resource,where=w)
    try:
        if len(r['_items']) == 0:
            api.post(resource, obj)
    except:
        pass
Пример #6
0
def unfollow(db, user, leader_id):
    # only unfollow someone if this user followed them,
    # and they've had some time to follow them back but didn't:
    with db, db.cursor() as cursor:
        twitter = database.get_twitter(cursor, leader_id)
        user_follow = database.get_user_follow(cursor, user.id, leader_id)
        user_unfollow = database.get_user_unfollow(cursor, user.id, leader_id)
        follower = database.get_twitter_follower(cursor, user.twitter_id,
                                                 leader_id)
    log(user, 'unfollowing %s followed at %s', twitter.api_id,
        user_follow.time if user_follow else None)
    if not user_follow:
        return warn(user, 'but they were never followed')
    if user_unfollow:
        return warn(user, 'but they were already unfollowed at %s',
                    user_unfollow.time)
    if user_follow.time > now() - UNFOLLOW_LEADERS_PERIOD:
        return warn(user, 'but they were followed too recently')
    if follower and user_follow.time > now() - UNFOLLOW_FOLLOWERS_PERIOD:
        return warn(
            user,
            'but they were followed too recently for someone who followed back'
        )

    try:
        api.post(user, 'friendships/destroy', user_id=twitter.api_id)
    except requests.exceptions.HTTPError as e:
        if e.response.status_code != 404:
            raise e
        return warn(user, 'failed to unfollow %s [%d %s]', twitter.api_id,
                    e.response.status_code, e.response.text)

    with db, db.cursor() as cursor:
        database.add_user_unfollow(cursor, user.id, leader_id)
        database.delete_twitter_follower(cursor, leader_id, user.twitter_id)
Пример #7
0
def kigen(memberId, entryDate, output):
    api.post(
        URL + API_KEY, {
            'payload':
            (None,
             '{"channel":"' + CHANNEL + '", "username":"******", "text":"' + output + '", "icon_emoji": ":ghost:"}'),
        })
Пример #8
0
def out(memberId, entryDate, output):
    api.post(
        URL + API_KEY, {
            'payload':
            (None,
             '{"channel":"' + CHANNEL + '", "username":"******", "text":"' + output + '", "icon_emoji": ":watch:"}'),
        })
Пример #9
0
 def test_preferred_uid_clash(self):
     pref_uid = "rtt"
     uid = api.post(ApiTest.CONTENT, preferred_uid=pref_uid)
     self.assertEqual(uid, pref_uid)
     ret_content = api.retrieve(pref_uid)
     self.assertEqual(ret_content, ApiTest.CONTENT)
     uid2 = api.post(ApiTest.CONTENT, preferred_uid=pref_uid)
     self.assertNotEqual(uid2, uid)
Пример #10
0
def parse(data):
    parameters = [
        json.loads(unicode(p, 'utf-8')) for p in data.read().split(',,')
        if p != ''
    ]

    logging.info(parameters[0]['data'])

    try:
        api.post(parameters[0]['data'])
    except Exception as e:
        raise e
Пример #11
0
def index_file(url):
    print(f'indexing {url}')
    # parse file by given URL
    resp = requests.get(url=TIKA_HOST + '/api/tika/parse',
                        params={'url': url},
                        headers=api.stdHeaders,
                        timeout=api.TIMEOUT)
    resp.raise_for_status()
    result = resp.json()

    api.login("system", os.getenv("SYSTEM_PWD"))

    meta = result['metadata']

    id = search_doc(url)
    author = meta.get('author', '')
    if author == '':
        author = meta.get('creator', '')
    author_id = search_person(author)
    if author_id is None:
        person = {'name': author}
        person = api.post('/api/data/person', person)
        author_id = person['uid']

    keyword = split_keywords(meta.get('keyword', ''))
    keyword.extend(split_keywords(meta.get('keywords', '')))
    keyword.append('book')
    keyword = list(set([k.strip() for k in keyword if len(k.strip()) > 0]))

    tags = make_tags(keyword)
    meta.pop('keyword', None)
    meta.pop('keywords', None)

    doc = meta
    doc['url'] = url
    doc['text'] = result['text']
    doc['author'] = {'uid': author_id}
    # todo fix thumbnail generation
    # doc['thumbnail_url'] = thumb(url)

    if id is None:
        doc = api.post('/api/data/document', doc)
        id = doc['uid']
    else:
        doc = api.put(f'/api/data/document/{id}', doc)

    # set tags
    edges = [[id, 'tag', t] for t in tags]
    api.update_graph(edges)
    return doc
Пример #12
0
def get_keeper_ids(db, user, retry=True):
    try:
        data = api.get(user, 'lists/members', slug='fllow-keepers',
                       owner_screen_name=user.screen_name, count=5000, skip_status=True)
    except requests.exceptions.HTTPError as e:
        warn(user, 'fllow-keepers list not found')
        if e.response.status_code == 404 and retry:
            api.post(user, 'lists/create', name='fllow keepers', mode='private',
                     description='fllow will not unfollow users in this list')
            return get_keeper_ids(db, user, retry=False)
        raise e

    with db, db.cursor() as cursor:
        return database.add_twitter_api_ids(cursor, [user['id'] for user in data['users']])
Пример #13
0
def get_captcha(browser):
    fail_count = 0
    while True:
        time.sleep(1)
        if fail_count > 0:
            time.sleep(2)
        try:
            imgA = browser.find_element_by_xpath('//*[@id="targetImgie"]')
            fail_count += 1
        except:
            return True
        print('captcha found!')
        imgB = browser.find_element_by_xpath('//*[@id="bgImgie"]')
        urllib.request.urlretrieve(imgA.get_attribute('src'), 'A.png')
        urllib.request.urlretrieve(imgB.get_attribute('src'), 'B.png')
        image.merge_captcha()
        print('sending request...')
        result = api.post()
        result = json.loads(result)
        print(result)
        try:
            pos = result['data']['val'].split('|')
        except:
            print('request error! refreshing...')
            browser.refresh()
            continue
        for point in pos:
            x, y = point.split(',')
            click(browser, imgB, int(x), int(y))
            time.sleep(0.3)
        submit = browser.find_element_by_xpath('//*[@id="submitie"]')
        submit.click()
        if fail_count >= 10:
            return False
Пример #14
0
    def gera_pessoas(self):
        '''
        Método auxiliar para inserir dados de pessoas
        para os testes.
        '''

        url = '/person/'
        api = webtest.TestApp(self.base_url)
        ids = [
            100001409463894, 100003025997960, 100002677114948, 759574065,
            1619357922, 100001227665412, 100001606531815, 100004616023613,
            100003288611757
        ]
        for i in ids:
            api.post(url, {'facebookId': i})
        return ids
Пример #15
0
def put_property_if_not_exist(resource, obj, w, property_name, prop):
    r = api.get(resource, where=w)
#    print(r)
#    print(obj)
#    print(w)
#    print(property_name)
#    print(prop)
    if len(r['_items']) == 0:
        obj[property_name] = [prop]
        r = api.post(resource, obj)
        obj_old = r['_items'][0]
    else:
        obj_old = r['_items'][0]
        for pr in obj_old:
            if pr[0] != '_':
                try:
                    obj[pr]
                except:
                    obj[pr] = obj_old[pr]
        try:
            properties = r['_items'][0][property_name]
        except:
            properties = []
        already_in = False
        for pr in properties:
            if pr == prop:
                already_in = True
        if not already_in:
            properties.append(prop)
            obj[property_name] = properties
            r = api.put(resource + "/" + r["_items"][0]["_id"], obj)
Пример #16
0
def main():

    if len(sys.argv) is not 2:
        usage()
        return

    document = sys.argv[1]

    with open(document, 'r') as handle:
        headers = ['blank', 'date', 'name', 'time', 'email', 'phone']
        headers.extend(['comment', 'major', 'nPeople'])
        doc = csv.DictReader(handle, headers)
        remaining = 4
        for family in doc:

            #skip the first 4 lines
            if remaining is not 0:
                remaining -= 1
                continue

            #skip empty rows
            if family['date'] == '':
                continue

            tour = {}
            tour['date'] = 'November ' + family['date'] + " " + family['time']
            tour['name'] = family['name']
            tour['email'] = family['email']
            tour['phone'] = family['phone']
            tour['comments'] = family['comment']
            tour['majorsOfInterest'] = family['major']
            tour['nVisitors'] = family['nPeople']
            pprint(post(tour))
Пример #17
0
def make_tag(text):
    id = find_tag(text)
    if id is not None:
        return id

    tag = {'text': text}
    resp = api.post('/api/data/tag', tag)
    return resp['uid']
Пример #18
0
 def update_mtime(self, mtime: int):
     data = {'inode': self.inode(), 'mtime': mtime}
     (success, response) = api.post('inodeUpdate', data=data)
     if not success:
         if response == 25:
             raise FUSEError(errno.ENOENT)
         else:
             raise FUSEError(errno.EREMOTEIO)
Пример #19
0
def make_tag(text):
    id = find_tag(text)
    if id is not None:
        return {'uid': id}

    tag = {'text': text}
    tag = api.post('/api/data/tag', tag)
    return {'uid': tag['uid']}
Пример #20
0
def sendtext(content):
    xml = api.get('account/rate_limit_status')
    xml = etree.fromstring(xml)
    limit_num = xml[1].text
    if int(limit_num) == 0:
        return
    code = api.post('statuses/update', status=content)
    logbook.info("sent!")
Пример #21
0
def sendtext(content):
    xml = api.get('account/rate_limit_status')
    xml = etree.fromstring(xml)
    limit_num = xml[1].text
    if int(limit_num) == 0:
        return
    code = api.post('statuses/update',status=content)
    logbook.info("sent!")
Пример #22
0
 def get_multiple(**kwargs):
     """ Given multiple gene IDs, retrieve all genes.
     :returns genes: list of genes with the IDs specified.
     """
     results = post(endpoints['post-gene'], params=kwargs)
     genes = []
     for r in results:
         genes.append(Gene(r))
     return genes
Пример #23
0
 def get_multiple(**kwargs):
     """ Given multiple variant IDs, retrieve all variants.
     :returns variants: list of variants with the IDs specified.
     """
     results = post(endpoints['post-variant'], params=kwargs)
     variants = []
     for r in results:
         variants.append(Variant(r))
     return variants
Пример #24
0
 def get_multiple(**kwargs):
     """ Given multiple variant IDs, retrieve all variants.
     :returns variants: list of variants with the IDs specified.
     """
     results = post(endpoints['post-variant'], params=kwargs)
     variants = []
     for r in results:
         variants.append(Variant(r))
     return variants
Пример #25
0
def main(user, path, params):
    db = database.connect()

    with db, db.cursor() as cursor:
        user = database.get_user(cursor, user)

    data = api.post(user, path, **params)

    print(json.dumps(data, indent=2))
Пример #26
0
def new(public=None, description=None, content=None, filename=None):
    api.getCredentials()
    log.debug(
        "Command: New: public: '{0}' description: '{1}' filename: '{2}' content: '{3}'."
        .format(str(public), str(description), str(filename), str(content)))

    if public == None:
        if _supress:
            public = defaults.public
        else:
            public = util.parseBool(
                util.readConsole(prompt='Public Gist? (y/n):', bool=True))

    if description == None:
        if _supress:
            description = defaults.description
        else:
            description = util.readConsole(prompt='Description:',
                                           required=False)

    if content == None and filename != None:
        if os.path.isfile(filename):
            content = util.readFile(filename)
        else:
            print("Sorry, filename '{0}' is actually a Directory.".format(
                filename))
            sys.exit(0)

    if content == None:
        if _supress:
            content = defaults.content
        else:
            content = util.readConsole()

    if filename == None:
        filename = defaults.file

    log.debug("Creating Gist using content: \n" + content)

    url = '/gists'
    data = {
        'public': str(public).lower(),
        'description': description,
        'files': {
            os.path.basename(filename): {
                'content': content
            }
        }
    }
    log.debug('Data: ' + str(data))

    gist = api.post(url, data=data)

    pub_str = 'Public' if gist['public'] else 'Private'
    print("{0} Gist created:Id '{1}' and Url: {2}".format(
        pub_str, gist['id'], gist['html_url']))
Пример #27
0
 def find_multiple_by(**kwargs):
     """ Given a list of queries and key-value params.
     Find all of the genes that match any of the given criteria.
     :returns genes: list of matches for hte queries provieded.
     """
     results = post(endpoints['post-query'], params=kwargs)
     genes = []
     for r in results:
         genes.append(Gene(r))
     return genes
Пример #28
0
 def find_multiple_by(**kwargs):
     """ Given a list of queries and key-value params.
     Find all of the variants that match any of the given criteria.
     :returns variants: list of matches for hte queries provieded.
     """
     results = post(endpoints['post-query'], params=kwargs)
     variants = []
     for r in results:
         variants.append(Variant(r))
     return variants
Пример #29
0
def sendtext():
    xml        = api.get('account/rate_limit_status')
    xml        = etree.fromstring(xml)
    limit_num  = xml[1].text
    if string.atoi(limit_num) == 0:
        return
    id,content = message.get_text()
    if id==0:return
    code       = api.post('statuses/update',status=content)
    #if code == 1:
    message.over(id)
Пример #30
0
    def get_regions(self, body):
        result = post(self.app_key, self.app_secret,
                      "/artemis/api/resource/v1/regions", "POST", self.ip,
                      self.port, body, self.https)

        result = json.loads(result)

        if result["code"] != '0':
            return []

        return result['data']['list']
Пример #31
0
def directmsg():
    xml = api.get('direct_messages/inbox')
    if xml:
        xml    = etree.fromstring(xml)
        num    = len(xml)
        if num>0:
            for i in range(num):
                id     = xml[i][0].text
                msg    = xml[i][1].text
                message.save(msg,2)
                code   = api.post('direct_messages/destroy',id=id)
                while code != 1:code,xml = api.fanfou('direct_messages/destroy',{'id':id})
Пример #32
0
def update_outsiders(db, user, outsider_ids, retry=True):
    try:
        data = api.get(user, 'lists/members', slug='fllow-outsiders',
                       owner_screen_name=user.screen_name, count=5000, skip_status=True)
    except requests.exceptions.HTTPError as e:
        warn(user, 'fllow-outsiders list not found')
        if e.response.status_code == 404 and retry:
            api.post(user, 'lists/create', name='fllow outsiders', mode='private',
                     description="users you manually followed / fllow didn't automatically follow")
            return update_outsiders(db, user, outsider_ids, retry=False)
        raise e

    current_api_ids = {user['id'] for user in data['users']}
    with db, db.cursor() as cursor:
        api_ids = database.get_twitter_api_ids(cursor, outsider_ids)

    added_api_ids = list(api_ids - current_api_ids)
    log(user, 'adding %d outsiders', len(added_api_ids))
    for i in range(0, len(added_api_ids), 100):
        api.post(user, 'lists/members/create_all', slug='fllow-outsiders',
                 owner_screen_name=user.screen_name,
                 user_id=','.join(str(api_id) for api_id in added_api_ids[i:i+100]))

    removed_api_ids = list(current_api_ids - api_ids)
    log(user, 'removing %d outsiders', len(removed_api_ids))
    for i in range(0, len(removed_api_ids), 100):
        api.post(user, 'lists/members/destroy_all', slug='fllow-outsiders',
                 owner_screen_name=user.screen_name,
                 user_id=','.join(str(api_id) for api_id in removed_api_ids[i:i+100]))
Пример #33
0
def get_keeper_ids(db, user, retry=True):
    try:
        data = api.get(user,
                       'lists/members',
                       slug='fllow-keepers',
                       owner_screen_name=user.screen_name,
                       count=5000,
                       skip_status=True)
    except requests.exceptions.HTTPError as e:
        warn(user, 'fllow-keepers list not found')
        if e.response.status_code == 404 and retry:
            api.post(user,
                     'lists/create',
                     name='fllow keepers',
                     mode='private',
                     description='fllow will not unfollow users in this list')
            return get_keeper_ids(db, user, retry=False)
        raise e

    with db, db.cursor() as cursor:
        return database.add_twitter_api_ids(
            cursor, [user['id'] for user in data['users']])
Пример #34
0
def follow(db, user, leader_id):
    # only follow someone if this user hasn't already followed them,
    # and hasn't followed anyone too recently,
    # and hasn't followed too many people recently:
    with db, db.cursor() as cursor:
        twitter = database.get_twitter(cursor, leader_id)
        user_follow = database.get_user_follow(cursor, user.id, leader_id)
        last_follow_time = database.get_user_follows_last_time(cursor, user.id)
        follows_today = database.get_user_follows_count(
            cursor, user.id,
            now() - DAY)
    log(user, 'following %s last followed at %s and %d follows today',
        twitter.api_id, last_follow_time, follows_today)
    if user_follow:
        return warn(user, 'but they were already followed at %s',
                    user_follow.time)
    if last_follow_time and last_follow_time > now() - FOLLOW_PERIOD:
        return warn(user, 'but followed too recently')
    if follows_today >= MAX_FOLLOWS_PER_DAY:
        return warn(user, 'but too many follows today')

    try:
        api.post(user, 'friendships/create', user_id=twitter.api_id)
        followed = True
    except requests.exceptions.HTTPError as e:
        if e.response.status_code != 403:
            raise e
        # 403 can mean blocked or already following, so we mark as followed
        warn(user, 'marking %s as followed [%d %s]', twitter.api_id,
             e.response.status_code, e.response.text)
        followed = False

    with db, db.cursor() as cursor:
        database.add_user_follow(cursor, user.id, leader_id)
        if followed:
            database.update_twitter_followers(cursor, leader_id,
                                              [user.twitter_id])
Пример #35
0
def directmsg():
    xml = api.get('direct_messages/inbox')
    if xml:
        xml = etree.fromstring(xml)
        num = len(xml)
        if num > 0:
            for i in range(num):
                id = xml[i][0].text
                msg = xml[i][1].text
                logbook.info(msg.encode("utf8"))
                sendtext(msg.encode("utf8"))
                code = api.post('direct_messages/destroy', id=id)
                logbook.info("destory")
                while code != 1:
                    code, xml = api.fanfou('direct_messages/destroy',{'id':id})
Пример #36
0
def post():
    """Post a new pastebin"""
    content = request.forms.get('content')
    if content == "":
        abort(404, "You must provide a content")
    preferred_uid = request.forms.get('puid')
    if not preferred_uid:
        preferred_uid = None
    uid = api.post(content, preferred_uid=preferred_uid)
    url = '%s%s' % (request.url, uid)
    raw_url = url + '/raw'
    if request.forms.get('from_form'):
        return template('paste_done', url=url, raw_url=raw_url)
    else:
        return HTTPResponse(raw_url, status=201, header={'Location': raw_url})
Пример #37
0
def directmsg():
    xml = api.get('direct_messages/inbox')
    if xml:
        xml = etree.fromstring(xml)
        num = len(xml)
        if num > 0:
            for i in range(num):
                id = xml[i][0].text
                msg = xml[i][1].text
                logbook.info(msg.encode("utf8"))
                sendtext(msg.encode("utf8"))
                code = api.post('direct_messages/destroy', id=id)
                logbook.info("destory")
                while code != 1:
                    code, xml = api.fanfou('direct_messages/destroy',
                                           {'id': id})
Пример #38
0
    async def rename(self, inode_p_old: int, name_old: bytes, inode_p_new: int,
                     name_new: bytes, flags, ctx: pyfuse3.RequestContext):
        """
        Rename a directory entry.

        This method must rename name_old in the directory with inode parent_inode_old to name_new in
        the directory with inode parent_inode_new. If name_new already exists, it should be overwritten.

        flags may be RENAME_EXCHANGE or RENAME_NOREPLACE. If RENAME_NOREPLACE is specified, the
        filesystem must not overwrite name_new if it exists and return an error instead. If
        RENAME_EXCHANGE is specified, the filesystem must atomically exchange the two files,
        i.e. both must exist and neither may be deleted.

        ctx will be a RequestContext instance.

        Let the inode associated with name_old in parent_inode_old be inode_moved, and the inode
         associated with name_new in parent_inode_new (if it exists) be called inode_deref.

        If inode_deref exists and has a non-zero lookup count, or if there are other directory
        entries referring to inode_deref), the file system must update only the directory entry for
        name_new to point to inode_moved instead of inode_deref. (Potential) removal of inode_deref
        (containing the previous contents of name_new) must be deferred to the forget method to be
        carried out when the lookup count reaches zero (and of course only if at that point there
        are no more directory entries associated with inode_deref either).
        """
        if flags != 0:
            raise FUSEError(errno.EINVAL)

        data = {
            'inode_p': inode_p_old,
            'name': name_old.decode(),
            'new_parent': inode_p_new,
            'new_name': name_new.decode()
        }
        (success, response) = api.post('inodeMove', data=data)
        if not success:
            if response == 9:  # MISSING_WRITE_ACCESS
                raise (FUSEError(errno.EACCES))  # Permission denied
            if response == 22:  # INODE_NOT_EXISTS
                raise (FUSEError(errno.ENOENT))  # No such file or directory
            elif response == 23:  # IS_A_FILE
                raise (FUSEError(errno.EEXIST))  # File exists
            elif response == 24:  # NAME_ALREADY_EXISTS
                raise (FUSEError(errno.EEXIST))  # File exists
            else:
                log.warning('Rename error, response: %s', response)
                raise (FUSEError(errno.EREMOTEIO))  # Remote I/O error
Пример #39
0
 def run(self):
     response, id, link = api.post(self._comment, self._thread_id,
                                   OPTS.board, OPTS.passcode,
                                   self._pic_file)
     print('')
     if response['Error']:
         print(response)
         if response['Error'] == -8:
             print('Retry...')
             self._retry_pause()
             self.run()
     else:
         print(self._reply_to)
         print(self._comment)
         if self._pic_file:
             print('[' + os.path.basename(self._pic_file) + ']')
         print(link)
         self._watch_for_replies(id)
Пример #40
0
 async def unlink(self, inode_p: int, name: bytes,
                  ctx: pyfuse3.RequestContext):
     (success, response) = api.post('inodeDelete',
                                    data={
                                        'inode_p': inode_p,
                                        'name': name.decode()
                                    })
     if not success:
         if response == 9:
             raise FUSEError(errno.EACCES)  # Permission denied
         elif response in [22, 23, 25]:
             raise FUSEError(
                 errno.ENOENT
             )  # No such file or directory. but wait, what?? should not be possible
         else:
             log.error('unlink error %s', response)
             raise (FUSEError(errno.EREMOTEIO))  # Remote I/O error
     log.debug('delete done')
Пример #41
0
def put_single_property_if_not_exist(resource, obj, w, property_name, prop):
    r = api.get(resource, where=w)
    if len(r['_items']) == 0:
        obj[property_name] = prop
        r = api.post(resource, obj) 
        obj_old = r['_items'][0]
    else:
        obj_old = r['_items'][0]
        for pr in obj_old:
            if pr[0] != '_':
                try:
                    obj[pr]
                except:
                    obj[pr] = obj_old[pr]
        try:
            properti = r['_items'][0][property_name]
        except:
            obj[property_name] = prop
            r = api.put(resource + "/" + r["_items"][0]["_id"], obj)
Пример #42
0
    def get_camera_preview_url(self, camera_index, stream_type, protocol,
                               trans_mode, expand):
        result = post(
            self.app_key, self.app_secret,
            "/artemis/api/video/v1/cameras/previewURLs", "POST", self.ip,
            self.port, {
                "cameraIndexCode": camera_index,
                "streamType": stream_type,
                "protocol": protocol,
                "transmode": trans_mode,
                "expand": expand
            }, self.https)

        result = json.loads(result)

        if result["code"] != '0':
            return ''

        return result['data']['url']
Пример #43
0
def new (public=None,description=None,content=None,filename=None):
  api.getCredentials()
  log.debug ("Command: New: public: '{0}' description: '{1}' filename: '{2}' content: '{3}'.".format(str(public), str(description), str(filename), str(content)))

  if public == None:
    if _supress:
      public = defaults.public
    else:
      public = util.parseBool( util.readConsole(prompt='Public Gist? (y/n):', bool=True) )

  if description == None:
    if _supress:
      description = defaults.description
    else:
      description = util.readConsole(prompt='Description:', required=False)

  if content == None and filename != None:
    if os.path.isfile( filename ):
      content = util.readFile(filename)
    else:
      print "Sorry, filename '{0}' is actually a Directory.".format(filename)
      sys.exit(0)

  if content == None:
    if _supress:
      content = defaults.content
    else:
      content = util.readConsole()

  if filename == None:
    filename = defaults.file

  log.debug ("Creating Gist using content: \n" + content)

  url = '/gists'
  data = {'public': str(public).lower(), 'description': description, 'files': { os.path.basename(filename): { 'content': content } } }
  log.debug ('Data: ' + str(data))

  gist = api.post(url, data=data)

  pub_str = 'Public' if gist['public'] else 'Private'
  print "{0} Gist created:Id '{1}' and Url: {2}".format(pub_str, gist['id'], gist['html_url'])
Пример #44
0
def update_outsiders(db, user, outsider_ids, retry=True):
    try:
        data = api.get(user,
                       'lists/members',
                       slug='fllow-outsiders',
                       owner_screen_name=user.screen_name,
                       count=5000,
                       skip_status=True)
    except requests.exceptions.HTTPError as e:
        warn(user, 'fllow-outsiders list not found')
        if e.response.status_code == 404 and retry:
            api.post(
                user,
                'lists/create',
                name='fllow outsiders',
                mode='private',
                description=
                "users you manually followed / fllow didn't automatically follow"
            )
            return update_outsiders(db, user, outsider_ids, retry=False)
        raise e

    current_api_ids = {user['id'] for user in data['users']}
    with db, db.cursor() as cursor:
        api_ids = database.get_twitter_api_ids(cursor, outsider_ids)

    added_api_ids = list(api_ids - current_api_ids)
    log(user, 'adding %d outsiders', len(added_api_ids))
    for i in range(0, len(added_api_ids), 100):
        api.post(user,
                 'lists/members/create_all',
                 slug='fllow-outsiders',
                 owner_screen_name=user.screen_name,
                 user_id=','.join(
                     str(api_id) for api_id in added_api_ids[i:i + 100]))

    removed_api_ids = list(current_api_ids - api_ids)
    log(user, 'removing %d outsiders', len(removed_api_ids))
    for i in range(0, len(removed_api_ids), 100):
        api.post(user,
                 'lists/members/destroy_all',
                 slug='fllow-outsiders',
                 owner_screen_name=user.screen_name,
                 user_id=','.join(
                     str(api_id) for api_id in removed_api_ids[i:i + 100]))
Пример #45
0
 def handle(self):
     """handle the depot of a new paste from an already alive
     connexion"""
     #handle the post request
     content = list()
     while 1:
         buf = self.request.recv(GeneralHandler.BUF_SIZE).decode("UTF-8")
         logging.debug("Uid buffer is :|%s|" % buf)
         #if buf == b'\xff\xec':
         #    telnet support
         #    break
         if '\x0a' in buf:
             #netcat support
             content += buf
             break
         content += buf
     decoded_content = "".join(content).rstrip()
     logging.debug("Content uploaded is :|%s|" % decoded_content)
     uid = api.post(decoded_content)
     logging.debug("Uid is :|%s|" % uid)
     state = self.request.sendall(uid.encode('UTF-8'))
     if state:
         logging.debug('Data not fully transmitted')
         logging.warning('The data sent have not been transmitted properly')
Пример #46
0
 def test_preferred_uid(self):
     pref_uid = "burger"
     uid = api.post(ApiTest.CONTENT, preferred_uid=pref_uid)
     self.assertEqual(uid, pref_uid)
     ret_content = api.retrieve(pref_uid)
     self.assertEqual(ret_content, ApiTest.CONTENT)
Пример #47
0
def sendTransaction(**kw):
    tx = crypto.bakeTransaction(**dict([k, v] for k, v in kw.items() if v))
    result = api.post("/peer/transactions", transactions=[tx])
    if result["success"]:
        result["id"] = tx["id"]
    return result
Пример #48
0
def notificationUser(id):
    res = api.get("notifications/show",{"id":id},login=True)["response"]
    res_ = api.post("notifications/read",{"id":id},login=True)["response"]
    return redirect("/u/"+res["targetUser"]["screenName"])
Пример #49
0
def notificationPost(id):
    res = api.get("notifications/show",{"id":id},login=True)["response"]
    res_ = api.post("notifications/read",{"id":id},login=True)["response"]
    return redirect("/p/"+res["targetPost"]["id"])
Пример #50
0
def tweet():
    secret.logic.filter_tweet()

    api.post('statuses/update', status=flask.request.values['status'])
    return 'ok'
Пример #51
0
def init():
    for user in users:
        ensure_user(user)
    for channel in channels:
        api.post('/api/data/channel', channel)
Пример #52
0
def ensure_user(user):
    if not user_exists(user):
        api.post('/api/data/user', user)
Пример #53
0
 def test_wrong_expiry_policy(self):
     with self.assertRaises(ValueError):
         api.post(ApiTest.CONTENT, expiry_policy=99)
Пример #54
0
 def test_normal_retrieve(self):
     uid = api.post(ApiTest.CONTENT)
     ret = api.retrieve(uid)
     self.assertEqual(ApiTest.CONTENT, ret)
                item[names[j]] = it
            j = j + 1
        if i > 0:
            data.append(item)
        i = i + 1

results = []
check = 0
for row in data:
    summary = []
    for item in summary_items:
        summary.append({'name':item,'value':int(row[item])})
    counts = []
    for party in parties:
        counts.append({'votes': int(row[party]), 'option_identifier': n2id[party]})
    result = {
        "election_id": election_id,
        "area_id": row['municipality']+'-'+row['district'],
        'area_classification': 'district',
        'summary': summary,
        'counts': counts
    }
    check = check + int(row['1'])
    #r = api.post("results",result)
    results.append(result)
    #if r['_status'] == 'ERR':
    #    print(result['area_id'],r['_issues'])
        #raise(Exception)
    
api.post("results",results)
Пример #56
0
 def test_empty_post(self):
     post_content = ""
     uid = api.post(post_content)
     self.assertIsNone(uid)
Пример #57
0
        results = api.get('results',where={"election_id":election_id},page=p)
        for result in results["_items"]:
            adding(result,result["area_id"],data,parents,election_id)
            #if result["area_id"] == '506320-3':
                #raise(Exception)

    out = []
    for area_id in data:
        item = {'summary':[],'counts':[],'area_classification':data[area_id]['classification'],'election_id': election_id, "area_id":area_id}
        for s in data[area_id]['summary']:
            item['summary'].append({'name':s,'value':data[area_id]['summary'][s]})
        for s in data[area_id]['counts']:
            item['counts'].append({'option_identifier':s,'votes':data[area_id]['counts'][s]})
        out.append(item)

    api.post("results",out)    
   
#final:
data = {}
data['cz-kraje'] = {'summary':{},'counts':{},'classification':'provinces'}
parent_election_id = 'cz-kraje-2012'
parent_id = 'cz-kraje'
for province in provinces:
    election_id = 'cz-kraje-'+province[0]+'-2012'  
    results = api.get('results',where={"election_id":election_id,"area_id":province[0]})
    result = results["_items"][0]
    for s in result['summary']:
        try:
            data[parent_id]['summary'][s['name']] = data[parent_id]['summary'][s['name']] + int(s['value'])
        except:
            data[parent_id]['summary'][s['name']] = int(s['value'])
Пример #58
0
}

admin = {
    "email": "*****@*****.**",
    "pass": "******"
}

# as ADMIN
api.login(admin['email'],admin['pass'])

data = {
    "name": "Radnice",
    "classification": "city halls",
    "founding_date": "2014-10-01"
}
r = api.post("organizations",data=data)
org_id = int(api.post_id(r))

data = {
    "name": "Plasy",
    "classification": "city hall",
    "founding_date": "2014-10-01",
    "parent_id": org_id
}
r = api.post("organizations",data=data)
org_id = int(api.post_id(r))

params = {
    "email": "eq." + author['email']
}
user = api.get_one("users",params=params)