Skip to content

Instantly share code, notes, and snippets.

@anujdeshpande
Last active August 29, 2015 14:18
Show Gist options
  • Save anujdeshpande/0ddf9d4b7d315c6b818e to your computer and use it in GitHub Desktop.
Save anujdeshpande/0ddf9d4b7d315c6b818e to your computer and use it in GitHub Desktop.
import os, re
from PyPDF2 import PdfFileMerger, PdfFileReader
pages = ['ADS786x',
'ADT7310',
'API-Documentation',
'Analog-to-digital-converter',
'BBIOServer',
'DACx311',
'Digital-IO',
'EventIO',
'GSoC-2014-ideas',
'GSoC-2014',
'Home',
'Installing-PyBBIO',
'Interrupts',
'Library-development',
'Library-tutorial',
'MAX31855',
'MMA7660',
'PhantStream',
'Pulse-width-modulation',
'RotaryEncoder',
'SPI',
'SafeProcess',
'Serial',
'Servo',
'Similar-projects',
'Software-SPI',
'The-Basics',
'Using-PyBBIO',
'WebCam',
'i2C']
gitprint_url='https://gitprint.com/graycatlabs/PyBBIO/wiki/'
for i in pages:
os.system ('wget '+gitprint_url+i+'\?download')
os.system ('mv '+i+'?download'+' '+i+'.pdf')
# Need to create a sequence of pages to arrange them in one single PDF
# Sequence is :
# Installing-PyBBIO
# Using PyBBIO
# API Documentation
# Anything that's there in API Documentation
sequence = ['Installing-PyBBIO',
'Using-PyBBIO',
'API-Documentation']
# Get the API Documentation markdown for parsing
os.system ('wget https://github.com/alexanderhiam/PyBBIO/wiki/API-Documentation.md')
# Parse and get the sequence of all pages that are linked from here.
# This is (probably) the only page where new links will be added
pattern = re.compile('.*?\[(.*?)\]')
with open('API-Documentation.md') as f:
for line in f:
t = pattern.match(line)
if t:
#print line.split('wiki/')[1].split(')')[0]
sequence.append (line.split('wiki/')[1].split(')')[0])
#print sequence
sequence.append('Similar-projects')
merger = PdfFileMerger()
for filename in sequence:
merger.append(PdfFileReader(file(filename+'.pdf', 'rb')))
merger.write("PyBBIO.pdf")
#cleanup
for i in pages:
os.system ('rm '+i+'.pdf')
os.system('rm API-Documentation.md')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment