Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.77 KB | None | 0 0
  1. import time
  2. from splinter import Browser
  3. import sys
  4. import datetime as dt
  5. import os
  6. clear = lambda: os.system('cls')
  7. clear()
  8.  
  9. with Browser() as browser:
  10.     n1 = dt.datetime.now()
  11.     username = "sadones.jel@gmail.com"
  12.     password = "THISISMYPASSWORD"
  13.     #username = input("7thCav email ?")
  14.     #password = input("7thCav password?")
  15.     id = input("7thCav OLD MILPAC ID?")
  16.     newId = input("7Cav NEW MILPAC ID?")
  17.     url = "http://backup.7thcavalry.us/index.php?app=core&module=global&section=login"
  18.     browser.visit(url)
  19.     browser.find_by_id('ips_username').fill(username)
  20.     browser.find_by_id('ips_password').fill(password)
  21.     browser.find_by_css('.input_submit').first.click()
  22.     browser.visit("http://backup.7thcavalry.us/milpacs/soldierprofile.php?uniqueid=" + str(id))
  23.     dates = []
  24.     records = []
  25.     tables = browser.find_by_css(".row2").find_by_tag("table")
  26.     name = browser.find_by_xpath('//*[@id="content"]/div[3]/table[2]/tbody/tr[1]/td/b/font').first.text
  27.     print("---OLD PROFILE---")
  28.     print(name)
  29.     print("-----------------")
  30.     for table in tables:
  31.         if(len(table.find_by_tag("td")) == 2):
  32.             dates.append( table.find_by_tag("td").find_by_tag("font").first.text)
  33.             string = table.find_by_tag("td").last.text
  34.             if(string.find(" (citation)") != -1):
  35.                 string = string.replace(" (citation)", "")
  36.             if(string.find(" (Citation)") != -1):
  37.                 string = string.replace(" (Citation)", "")
  38.             records.append(' ' + string)
  39.     totalRecords = len(dates)
  40.     print("Found " + str(totalRecords) + " records for user ID: " + str(id))
  41.     print("Copying data has completed.")
  42.     print("Going to new 7Cav Website")
  43.    
  44.  
  45.     browser.visit("https://7cav.us/rosters/profile?uniqueid=" + str(newId))
  46.     browser.find_by_xpath('//*[@id="navigation"]/div/nav/div/ul[2]/li/label/a').click()
  47.     time.sleep(1)
  48.    
  49.     #Log in to new website
  50.     browser.find_by_id("LoginControl").fill(username)
  51.     browser.find_by_id("ctrl_password").fill(password)
  52.     browser.find_by_xpath('//*[@id="login"]/div/dl[3]/dd/input').click()
  53.     print("---NEW PROFILE---")
  54.     print(browser.find_by_css('.titleBar').text)
  55.     print("-----------------")
  56.     print("Make sure the new MILPAC is EMPTY. There can not be ANY Service Records. AND")
  57.     confirm = input("Do these two profiles match? Enter n to stop program! Press ENTER to continue")
  58.     if(confirm == "n" or confirm == "N"):
  59.         sys.exit("Profiles were not the same. Shutting down")
  60.    
  61.     clear()
  62.     #Loop times
  63.     for x in range(0, len(dates)):
  64.     #for x in range(0, 2):
  65.         #Button --> Add new record
  66.         browser.find_by_xpath('//*[@id="content"]/div/div/div[1]/div/a[4]').click()
  67.         print("Record: " + str(x))
  68.         print("Entering record " + records[x])
  69.         print("Entering record with date: " + dates[x])
  70.         print("------")
  71.         #Fill in date
  72.         browser.find_by_id('ctrl_record_date').click()
  73.         javascriptcode2 = '$(document).unbind("keydown");'
  74.         javascriptcode = '$("#ctrl_record_date").unbind("keydown");'
  75.         browser.execute_script(javascriptcode2)
  76.         browser.execute_script(javascriptcode)
  77.         browser.find_by_id('ctrl_record_date').fill(dates[x])
  78.  
  79.        
  80.         #Fill in record
  81.         with browser.get_iframe(0) as iframe:
  82.             iframe.find_by_xpath('/html/body/p').fill(records[x])
  83.  
  84.         #Click Save Changes
  85.         browser.find_by_xpath('//*[@id="content"]/div/div/form/dl/dd/input').click()
  86.     n2 = dt.datetime.now()
  87.     print("Copying has finished in ")
  88.     print((n2-n1).total_seconds())
  89.     print("seconds, for " + str(totalRecords) + " records.")
  90.     print("Programmed by CPL.Sadones.J")
  91.     input("Press any key to close this window.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement