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
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'])
from config import config from drupal_services import DrupalServices import os.path, sys, xlrd, time, mimetypes, xmlrpclib, pprint, base64 import unicodedata drupal = DrupalServices(config) book = xlrd.open_workbook("c:/MICE_LOG_AC_and_SD.xls") sh = book.sheet_by_index(1) rows=sh.nrows cols=sh.ncols m=sh.cell_value(rowx=2, colx=0) m=unicodedata.normalize('NFKD', m).encode('ascii','ignore') datasetname = m; #datasetname = 'Sys2_10January2013_1656_'; #datasetname = 'Sys2_10January2013_1656_' localpath = 'C:\\' filename = 'CI109' fileext = '.png' localname = localpath + filename + fileext remotename = filename + fileext os.chdir(localpath) # Create a language-neutral node, use the string 'und' to infer language-neutral node
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"]))