Last active
May 5, 2016 19:52
-
-
Save mutaku/b670b3a7dc06511cbf2b311adb4c2bbc to your computer and use it in GitHub Desktop.
Metamorph experiment description from PDF summary
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 characters
import PyPDF2 as PDF | |
import os | |
f = "C:\\User Data\\Nikon\\4_12_2016\\Multi Dimensional Acquisition Summar.pdf" | |
pdf_obj = PDF.PdfFileReader(open(f, 'rb')) | |
pdf_text = pdf_obj.getPage(0).extractText() | |
description = pdf_text.split('\n')[-1].split('Description')[-1].split('Printed on')[0] | |
# OR | |
descriptions = dict() | |
for root, dir, files in os.walk("C:\User Data\Nikon"): | |
if "Multi Dimensional Acquisition Summar.pdf" in files: | |
pdf_text = PDF.PdfFileReader(open(root+"\\Multi Dimensional Acquisition Summar.pdf", 'rb')).getPage(0).extractText() | |
name = '_'.join(root.split('\\')[-1].split('_')[0:3]) | |
descriptions[name] = pdf_text.split('\n')[-1].split('Description')[-1].rstrip('Page 1').split('Printed on') | |
# outputs: | |
descriptions.items()[0] | |
# ('8_12_2015', [u'PTP1del dual reporter 0-300 mM Pher *gradient*', u' Wed Aug 12 2015']) | |
with open("experiments.txt", 'a') as f: | |
f.writelines("{} :: {} :: {} \n".format(k, v[0], v[1] for k, v in descriptions.items())) | |
f.write('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment