示例#1
0
def sync(app):
  # url = 'https://live.runmyprocess.com/config/124158809/project/39799/collection/'

  url = 'https://live.runmyprocess.com/config/11761372963756487/project/58592/collection/?P_mode=TEST'

  r = requests.get(url, auth=RMPAuth('Basic ' + base64.b64encode(app.params.username+':'+app.params.password)))

  tree = et.fromstring(r.text)

  for child in tree.findall('{http://www.w3.org/2005/Atom}entry'):

    # defino a pagina
    cont = True
    page = 0
    conta = 0
    collection = child[0].text

    while cont == True:


      colUrl = 'https://live.runmyprocess.com/' + child[1].attrib['href'] + '/?P_mode=TEST&P_nb=1000&P_first=' + str(page * 1000)
      colR = requests.get(colUrl, auth=RMPAuth('Basic ' + base64.b64encode(app.params.username+':'+app.params.password)))

      if len(colR.json()) > 0:
        for item in colR.json():
          rutils.stablishCon(app.params.database, collection).insert(item)
          conta = conta + 1


      else:
        cont = False

      page = page + 1

    print "Success: " + str(conta) + " record(s) imported to local Mongo Database at " + collection
示例#2
0
def colxport(app):
  __page = 0
  __continue = True
  __records = 0

  while __continue == True:

    url = 'https://live.runmyprocess.com/pub/' + app.params.customerid + '/object/' + app.params.collection + '/?P_mode=' + app.params.mode + '&P_nb=1000&P_first=' + str(__page * 1000)

    r = requests.get(url, auth=RMPAuth('Basic ' + base64.b64encode(app.params.username+':'+app.params.password)))

    if r.status_code == 400:
      print 'Error: Unable to access RunMyProcess data, check your customerid and collection name.' + bcolors.FAIL + ' x' + bcolors.ENDC
      exit()
    elif r.status_code == 403:
      print 'Error: Unable to log in RunMyProcess, check your username and password.' + bcolors.FAIL + ' x' + bcolors.ENDC
      exit()
    else:
      if len(r.json()) > 0:
        for item in r.json():
          rutils.stablishCon(app.params.local_database, app.params.local_collection).insert(item)
          __records = __records + 1
      else:
        __continue = False

      __page = __page + 1

  print "Success: " + str(__records) + " record(s) imported to local Mongo Database " + bcolors.OKGREEN + u'\u2713' + bcolors.ENDC