Last active
February 20, 2024 08:27
-
-
Save glarrain/5861055 to your computer and use it in GitHub Desktop.
Revisions
-
German Larrain revised this gist
Jun 25, 2013 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,6 +40,8 @@ def download_attachments(attachments_metadata, dir=None): password = getpass.getpass("Account password: ") exit_status = os.system("bash login-to-PT.sh %s %s" % (user, password)) if exit_status: print("`login-to-PT.sh` failed. Exit code: %s" % exit_status) for metadata in attachments_metadata: file_id = metadata[0] @@ -49,6 +51,8 @@ def download_attachments(attachments_metadata, dir=None): print("downloading %s" % file_id) exit_status = os.system( 'bash get-attachment.sh %s "%s"' % (file_id, file_path)) if exit_status: print("`get-attachment.sh` failed. Exit code: %s" % exit_status) def main(): -
German Larrain revised this gist
Jun 25, 2013 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -85,7 +85,10 @@ def main(): get_attachment_metadata(element_attachment)) print("number of attachments: %s" % len(attachments_metadata)) if attachments_metadata: download_attachments(attachments_metadata, dir="attachments") else: print("[INFO] There are no attachments to be downloaded") if __name__ == '__main__': main() -
German Larrain revised this gist
Jun 25, 2013 . 1 changed file with 11 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,11 @@ def get_data_for_tag(tag_name): assert not node_attachment_tag.hasChildNodes() return node_attachment_tag.data return ( get_data_for_tag('id'), get_data_for_tag('filename'), get_data_for_tag('url'), ) def download_attachments(attachments_metadata, dir=None): @@ -43,7 +47,8 @@ def download_attachments(attachments_metadata, dir=None): filename = "%s - %s" % (file_id, server_filename) file_path = filename if dir is None else os.path.join(dir, filename) print("downloading %s" % file_id) exit_status = os.system( 'bash get-attachment.sh %s "%s"' % (file_id, file_path)) def main(): @@ -66,7 +71,8 @@ def main(): element_attachments = story.getElementsByTagName('attachments') if element_attachments: elements_attachments_dict[ix] = element_attachments print("number of stories with attachment(s): %s" % len(elements_attachments_dict)) for key in elements_attachments_dict: assert len(elements_attachments_dict[key]) == 1 @@ -75,7 +81,8 @@ def main(): story_elements_attachment = element_attachments.getElementsByTagName('attachment') assert len(story_elements_attachment) >= 1 for element_attachment in story_elements_attachment: attachments_metadata.append( get_attachment_metadata(element_attachment)) print("number of attachments: %s" % len(attachments_metadata)) download_attachments(attachments_metadata, dir="attachments") -
German Larrain revised this gist
Jun 25, 2013 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,22 @@ """Download stories attachments of a Pivotal Tracker project. The shell scripts in this directory do not contain the actual code of them but the instructions of how to get it. Since I'm not the author of those scripts, I can't post them in this gist without his permission. """ import getpass import os import pickle import xml.dom.minidom __version__ = '0.1.0' __author__ = 'German Larrain' def get_attachment_metadata(element_attachment): def get_data_for_tag(tag_name): elements_tag = element_attachment.getElementsByTagName(tag_name) -
German Larrain revised this gist
Jun 25, 2013 . 2 changed files with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ # get the second script in # http://veryuniquename.blogspot.com/2013/06/downloading-pivotal-tracker-attachments.html # (I haven't requested author's permission to post his code here) # and replace the last line with: # curl --silent --cookie cjar --cookie-jar cjar --output "$OUT_FILE" "$BASE_URL$ATT_ID" # (I had to quote $OUT_FILE so the filename could have spaces) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # get the first script in # http://veryuniquename.blogspot.com/2013/06/downloading-pivotal-tracker-attachments.html # (I haven't requested author's permission to post his code here) -
German Larrain revised this gist
Jun 25, 2013 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,11 +30,12 @@ def download_attachments(attachments_metadata, dir=None): filename = "%s - %s" % (file_id, server_filename) file_path = filename if dir is None else os.path.join(dir, filename) print("downloading %s" % file_id) exit_status = os.system('bash get-attachment.sh %s "%s"' % (file_id, file_path)) def main(): pickle_filename = raw_input("pickled file: ") # xml_stories_423507.p pickle_file = open(pickle_filename, 'rb') dom_as_xml = pickle.load(pickle_file) dom = xml.dom.minidom.parseString(dom_as_xml) -
German Larrain revised this gist
Jun 25, 2013 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,21 @@ """Download stories of a Pivotal Tracker project. You need the project ID (an int) and your API token. The latter can be obtained in ``https://www.pivotaltracker.com/profile``, or using curl:: $ curl -u username:password -X GET https://www.pivotaltracker.com/services/v3/tokens/active """ import getpass import pickle import urllib2 from xml.dom import minidom __version__ = '0.1.0' __author__ = 'German Larrain' project_id = raw_input("Project ID: ") auth_token = getpass.getpass("Auth token: ") -
German Larrain revised this gist
Jun 25, 2013 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ import getpass import pickle import urllib2 from xml.dom import minidom project_id = raw_input("Project ID: ") auth_token = getpass.getpass("Auth token: ") url_template = "http://www.pivotaltracker.com/services/v3/projects/%s/stories" url = url_template % project_id req = urllib2.Request(url, None, {'X-TrackerToken': auth_token}) response = urllib2.urlopen(req) dom = minidom.parseString(response.read()) -
glarrain created this gist
Jun 25, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import pickle import urllib2 from xml.dom import minidom project_id = 423507 # website auth_token = '5b18172ab0317ac609553bfb3ee60dee' get_stories_url = "http://www.pivotaltracker.com/services/v3/projects/%s/stories" % project_id url = get_stories_url req = urllib2.Request(url, None, {'X-TrackerToken': auth_token}) response = urllib2.urlopen(req) dom = minidom.parseString(response.read()) dom_as_xml = dom.toxml(encoding='utf-8') pickle_filename = "xml_stories_%s.p" % project_id pickle.dump(dom_as_xml, open(pickle_filename, 'wb')) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ import getpass import os import pickle import xml.dom.minidom def get_attachment_metadata(element_attachment): def get_data_for_tag(tag_name): elements_tag = element_attachment.getElementsByTagName(tag_name) assert len(elements_tag) == 1 element_tag = elements_tag[0] assert len(element_tag.childNodes) == 1 node_attachment_tag = element_tag.childNodes[0] assert not node_attachment_tag.hasChildNodes() return node_attachment_tag.data return get_data_for_tag('id'), get_data_for_tag('filename'), get_data_for_tag('url') def download_attachments(attachments_metadata, dir=None): user = raw_input("Account user: ") password = getpass.getpass("Account password: ") exit_status = os.system("bash login-to-PT.sh %s %s" % (user, password)) for metadata in attachments_metadata: file_id = metadata[0] server_filename = metadata[1] filename = "%s - %s" % (file_id, server_filename) file_path = filename if dir is None else os.path.join(dir, filename) print("downloading %s" % file_id) exit_status = os.system('bash get-attachment.sh %s "%s"' % (file_id, filepath)) def main(): pickle_filename = raw_input("pickled file name: ") pickle_file = open(pickle_file, 'rb') # "xml_stories_423507.p" dom_as_xml = pickle.load(pickle_file) dom = xml.dom.minidom.parseString(dom_as_xml) elements_stories = dom.getElementsByTagName('stories') assert len(dom.getElementsByTagName('stories')) == 1 element_stories = elements_stories[0] elements_story = element_stories.getElementsByTagName('story') print("number of stories: %s" % len(elements_story)) elements_attachments_dict = {} attachments_metadata = [] for ix, story in enumerate(elements_story): element_attachments = story.getElementsByTagName('attachments') if element_attachments: elements_attachments_dict[ix] = element_attachments print("number of stories with attachment(s): %s" % len(elements_attachments_dict)) for key in elements_attachments_dict: assert len(elements_attachments_dict[key]) == 1 element_attachments = elements_attachments_dict[key][0] story_elements_attachment = element_attachments.getElementsByTagName('attachment') assert len(story_elements_attachment) >= 1 for element_attachment in story_elements_attachment: attachments_metadata.append(get_attachment_metadata(element_attachment)) print("number of attachments: %s" % len(attachments_metadata)) download_attachments(attachments_metadata, dir="attachments") if __name__ == '__main__': main()