Ejemplo n.º 1
0
def deletenode(nodeid):
    from config import config
    from drupal_services import DrupalServices

    
    drupal = DrupalServices(config)

    print 'Attempting to delete nodeid: %s' % nodeid
    
    drupal.call('node.delete', int(nodeid))

    print "Node %s deleted." % nodeid
Ejemplo n.º 2
0
def uploadlog(path, contentType):
    """
    Uploads information from a behavior log to server.
        path is log path.
        contentType is which tab.
    """
    drupal = DrupalServices(config)

    rel = getBehaviorInfo(path)

    ''' EXAMPLE
    new_node = { 'language' : 'und',
                 'type': contentType,
                 'title': datasetname,
                 'field_clearing' : {'und' : { '0' : {'value': cleared}}},
                 'field_test_data' : { 'und' : { '0' : {'value' : testdata } }},
                 'field_id' : { 'und' : { '0' : {'value' : Id } }},
                 'field_date_headpost' : { 'und' : { '0' : {'value' : headpost } }},
                 'body': { 'und' : { '0' : {'value' : datasetname } }} ,
    }
    '''
    #CREATE A NEW NODE OBJECT OF KEY-VALUE PAIRS
    new_node = { 'language' : 'und',
                 'type': contentType,
                 'title': rel["logname"],
                 'field_id' : { 'und' : { '0' : { 'value' : rel['mouseid']}}},
                 'field_logpath' : { 'und' : { '0' : { 'value' : rel['logpath']}}},
                 'field_traveldistance' : { 'und' : { '0' : { 'value' : round(rel['traveldistance'],3)}}},
                 'field_rewardsperminute' : { 'und' : { '0' : { 'value' : round(rel['rewardsperminute'],3)}}},
                 'field_correctpercent' : { 'und' : { '0' : { 'value' : rel['correctpercent']}}},
                 'field_protocol' : { 'und' : { '0' : { 'value' : rel['protocol']}}},
    }

    #PUSH NODE
    node = drupal.call('node.create', new_node)

    print 'New node id: %s' % node['nid']

    #RECALL NODE
    created_node = drupal.call('node.retrieve', int(node['nid']))

    #PRINT INFORMATION
    print "Node information"
    print "Node title: %s " % (created_node['title'])
timestamp = str(int(time.time()))
# Create file_obj with encoded file data
file_obj = {
   'file': base64.b64encode(png_file),
    'filename': remotename,
    'filepath': 'public://' + remotename,
    #'filepath': 'sites/default/files/' + filename,
    #'filepath': filename,
    'filesize': filesize,
    'timestamp': timestamp,
  #'uid': user['uid'],
    'filemime': filemime,
}

f = drupal.call('file.create', file_obj)

imagefile = {'und': [{
    'status': '1',
     'filemime': 'image/png',
     'rdf_mapping': [],
     'uid': '4',
     'title': '',
     'timestamp': '1358411015',
     'uri': 'public://'+remotename,
     'fid': f['fid'],
     'alt': '',
     'filename': remotename
 }]}

Ejemplo n.º 4
0
api = twitter.Api(consumer_key='sAuaEfHd9Get3OftGMtOA',consumer_secret='KYfzEwwIjk33lfHDgAizRBfUTAfYYsh4es8qht0b5ls', access_token_key='82170753-7T5ujeHESZPH9nKlNYGU38Vh65Ao17SE4bfLtAnM', access_token_secret='CPgycQO1eIuUzgvm4WvBnDxhHxbC1Rt0PL7LTbdbdnc')

keywords = ['#sarmiento', '#once']
statuses = api.GetUserTimeline(id='@gcba')

result = dict()
for status in statuses:
  for key in keywords:
    hasKeyword = status.text.lower().find(key)
    if hasKeyword != -1:     
      if(result.has_key(key) and isinstance(result.get(key), list)):
        result.get(key).append(status)
      else:        
        result[key] = list()
        result.get(key).append(status)
        
drupal = DrupalServices(config)

for contents in result:
  for node in result[contents]:
    new_node = { 'type': contents.replace('#',''),
                 'title': node.text,
                 'field_uid':{'und':{'0':{'value':str(node.id)}}}
                }
    pprint.pprint(new_node)
    new_node_id = drupal.call('node.create', new_node)
    print 'New node id: %s' % new_node_id
   
print "STATUSES: "+ str(len(statuses))  
print "RESULTADOS: " + str(len(result["#once"]))