Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 05-24-2013, 03:29 PM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › Python v
« Previous 1 2 3 4 Next »

Mengubah .chm ke satu file .html (phyton)

Home General Computer Multimedia Business Lounge

Post Reply 
Tweet
Threaded Mode | Linear Mode
Mengubah .chm ke satu file .html (phyton)
12-11-2009, 12:56 AM
Post: #1
wenkhairu Offline
Administrator
*******
Administrators
Posts: 1,344
Joined: Dec 2009
Reputation: 260
Mengubah .chm ke satu file .html (phyton)
Code:
#!/usr/bin/python
# chm2html.py
# a simple python script to convert from .CHM into one single big HTML
#
#

from optparse import OptionParser
import sys, os, re

class joinedHTML:

  def __init__(self, jFileName, jMainFile):
    self.fileName = jFileName
    self.mainFile = jMainFile

  def makeTOC(self, hhcFile):

    hf = open(hhcFile, 'r')

    h = []
    self.daftarFile = []
    isi = hf.readlines()
    for a in isi:
      a = str.strip(a)
      if a.startswith('<param name="Local"'):
        h.append(a)

    for x in h:
      b = x.split('"')
      isiBeneran = b[3]
      self.daftarFile.append(isiBeneran)

    hf.close()

  def placeHTMLIntoStr(self, htmlFile):

    f = open(htmlFile,'r')
    self.htmlString = f.read()
    f.close()

  def splitInput(self):

    h = re.split('<body>|<body.+>|</body>', self.htmlString)

    self.header = h[0]
    self.body = h[1]
    self.footer = h[2]

  def getMain(self):

    self.placeHTMLIntoStr(self.daftarFile[0])
    self.splitInput()
    self.mainHeader = self.header
    self.mainFooter = self.footer
    self.mainBody = self.body

def main():

  usage = "%prog [options]"
  parser = OptionParser(usage)
  parser.add_option("-o", "--outfile", dest="fileName",
  help="Write output to FILENAME")
  parser.add_option("-c", "--hhcfile", dest="mainFile",
  help="A .hhc file which hold all contents definition")

  (options, args) = parser.parse_args()

  if options.fileName == None or options.mainFile == None:
  print 'Invalid arguments. Try -h or --help'
  sys.exit(2)

  # .hhc should be in current directory
  # and there's a directory named as the prefix
  # of .hhc (without extention)
  #

  if not os.path.isfile('./' + os.path.basename(options.mainFile)):
    print 'Error:'
    print os.path.basename(options.mainFile) + ' should be in current directory'
    sys.exit(2)
    directory = re.split('\.', os.path.basename(options.mainFile))

  if not os.path.isdir(directory[0]):
    print 'Error:'
    print 'No directory named ' + directory[0] + ' in current dir'
    sys.exit(2)

  htmlProcessed = joinedHTML(options.fileName, options.mainFile)
  htmlProcessed.makeTOC(options.mainFile)

  print 'Processing main file (' + options.mainFile + ') ... '
  htmlProcessed.getMain()
  print ''
  print 'Processing new contents ... '
  print ''

  newContents = htmlProcessed.mainHeader + '\r\n<body>' + htmlProcessed.mainBody

  print ''
  print 'Writing to ' + directory[0] + '/' + options.fileName
  print 'Using header and footer from ' + htmlProcessed.daftarFile[0]
  print ''

  iterasiKe = 0

  for fHTML in htmlProcessed.daftarFile:
    iterasiKe = iterasiKe + 1
    print 'Processing ' + str(iterasiKe) + ' of ' + str(len(htmlProcessed.daftarFile)) + '(' + fHTML + ') ...'

    try:
      htmlProcessed.placeHTMLIntoStr(fHTML)
      htmlProcessed.splitInput()
    except:
      print ''
      print 'Error while processing ' + fHTML
      print ''
      #sys.exit(2)

  newContents = newContents + htmlProcessed.body
  newContents = newContents + '\r\n</body>' + htmlProcessed.mainFooter
  print ''
  print 'Writing new contents to file ... '
  print ''
  outFile = open(directory[0] + '/' + options.fileName, 'w')
  outFile.write(newContents)
  print ''
  print 'Finished. Have a look at ' + directory[0] + '/' + options.fileName
  print ''

if __name__ == "__main__":
  main()

Untuk menggunakan script ini, silahkan meng-extract file .CHM dengan extract_chmLib dari proyek chmlib (http://www.jedrea.com/chmlib/). Setelah itu masuk ke direktori hasil extract dan jalankan sesuai dengan parameter yang diminta oleh script ini.

Script ini masih mempunyai sedikit kekurangan, yaitu direktori tempat file-file HTML yang telah diekstrak harus sama dengan nama file .HHC, misalnya jika hasil ekstrak menunjukkan ada file toc.hhc, maka direktori tempat hasil ekstrak harus bernama toc.
Visit this user's website Find all posts by this user
Quote this message in a reply
12-11-2009, 06:11 AM
Post: #2
kiddies Away
Administrator
*******
Administrators
Posts: 1,224
Joined: Dec 2009
Reputation: 40
RE: Mengubah .chm ke satu file .html (phyton)
chmlib << ini buat apa sih om....bisa kita bahas g rame2 disini.....
Find all posts by this user
Quote this message in a reply
12-11-2009, 10:59 AM
Post: #3
wenkhairu Offline
Administrator
*******
Administrators
Posts: 1,344
Joined: Dec 2009
Reputation: 260
RE: Mengubah .chm ke satu file .html (phyton)
gini om, shmlib itu adalh sebuah libraryyang di gunkana untuk membaca file dari Microsoft ITSS/CHM format files, misalny akn di varian linux salah satu lib yang kita butuhin unutk baca file chm adalah chmlib, untuk lebih jelas coba om ke sini aja om :):)
Visit this user's website Find all posts by this user
Quote this message in a reply
12-12-2009, 11:43 AM
Post: #4
kiddies Away
Administrator
*******
Administrators
Posts: 1,224
Joined: Dec 2009
Reputation: 40
RE: Mengubah .chm ke satu file .html (phyton)
hehehhe...ok deh om....ane udeh baca...cukup menarik om...ane cukup mengerti ajah, soalnya bukan bidang saya kalo python mah...walaupun dulu udeh pernah sampet ane pelajarin...hehehhe
Find all posts by this user
Quote this message in a reply
07-20-2012, 10:48 PM
Post: #5
asong123 Away
./Devilz Officer
Posts: 196
Joined: Jul 2010
Reputation: 1
RE: Mengubah .chm ke satu file .html (phyton)
makasih banget om... ketawa ijin ngembangin ini source..

Apps ini opensource kan ?
Visit this user's website Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  ScriptFinder.py, Searches for file contains dangerous command ditatompel 10 1,466 03-01-2012 08:55 PM
Last Post: badwolves1986
  contoh pemindahan posisi pointer file ce.dealova 5 1,079 02-24-2012 02:16 AM
Last Post: Fauzi Topan
  Script sederhana buat upload source file ke pastebin ditatompel 14 1,604 02-06-2012 03:43 PM
Last Post: ditatompel

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 05-24-2013, 03:29 PM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE