Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cookielib
- import urllib
- import urllib2
- import time
- import re
- import sys
- from HTMLParser import HTMLParser
- # Handles HTML data
- class MLStripper(HTMLParser):
- def __init__(self):
- self.reset()
- self.fed = []
- def handle_data(self, d):
- self.fed.append(d)
- def get_data(self):
- return ''.join(self.fed)
- # Gets string between two other strings in a string, stringception :D
- def find_between( s, first, last ):
- try:
- start = s.index( first ) + len( first )
- end = s.index( last, start )
- return s[start:end]
- except ValueError:
- print "error"
- # Gets rid of HTML tags, we need plain, legible english!
- def strip_tags(html):
- s = MLStripper()
- s.feed(html)
- return s.get_data()
- # Searches the html source of the RT page for a specific section that holds the description
- def getDescription(data):
- messageBody = find_between(str(data),'<div class="message-stanza plain-text-white-space">','</div>')
- if('<span' in messageBody):
- start = 0;
- end = messageBody.index('<span')
- return strip_tags(messageBody[start:end])
- return strip_tags(messageBody)
- # Searches the html source of the RT page for a specific section that holds the requestor's name
- def getContact(data):
- noHtml = strip_tags(data)
- requestors = find_between(noHtml,'Requestors:','Cc:')
- requestors = requestors.splitlines()
- requestors = filter(lambda x: not re.match(r'^\s*$', x), requestors)
- return requestors
- # IDs of the URL parameters in Salesforce
- subjectID = "&cas14="
- contactNameID = "&cas3="
- descriptionID="&cas15="
- accountNameID="&cas4="
- # The PHP code runs this script with an argument, which is from the user's input of RT URL
- url = sys.argv[1] # this will be the RT URL
- #url="https://rt.corexchange.com/Ticket/Display.html?id=231338"
- # Pretend this script is a browser so I can get some cookies!
- values = {'user' : '-snip-',
- 'pass' : '-snip-' }
- data = urllib.urlencode(values)
- cookies = cookielib.CookieJar()
- opener = urllib2.build_opener(
- urllib2.HTTPRedirectHandler(),
- urllib2.HTTPHandler(debuglevel=0),
- urllib2.HTTPSHandler(debuglevel=0),
- urllib2.HTTPCookieProcessor(cookies))
- response = opener.open(url, data)
- the_page = response.read()
- http_headers = response.info()
- # Prepares the info to be in a URL (no spaces, special characters, etc)
- final_subject = urllib.quote_plus(strip_tags(find_between(str(the_page),'<title>','</title>')))
- final_desc = urllib.quote_plus(getDescription(the_page))
- final_contact = urllib.quote_plus(getContact(the_page)[0])
- baseURL='https://na4.salesforce.com/500/e?retURL=%2F500%2Fo&RecordType=01260000000DZlO&ent=Case'
- addToURL='&CF00N60000001iwk8="8600%20Harry%20Hines%20Blvd/Fl-1/Ste-200/Rm-Data"&00N60000001iwkf=Maintenance%20Request&00N60000002AGjT=zColo&00N60000002DNPX=zColo&cas11=Customer'
- addToURL += subjectID + final_subject
- addToURL += contactNameID + final_contact
- addToURL += descriptionID + final_desc
- finalURL = baseURL + addToURL
- # This is the DATA that is passed back to PHP
- print find_between(str(the_page),'<title>','</title>') + "DELIMITER"
- print getDescription(the_page) + "DELIMITER"
- print getContact(the_page)[0] + "DELIMITER"
- print finalURL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement