Dhtml Table
Dhtml Portfolio
Portfolio with Graph
My thoughts, ideas and just a space for me to doodle.
Dhtml Portfolio
Portfolio with Graph
import time dayNames = {0:'Mon',1:'Tue',2:'Wed',3:'Thu', 4:'Fri',5:'Sat',6:'Sun'} monthNames = {1:'Jan',2:'Feb',3:'Mar',4:'Apr',5:'May',6:'Jun',7:'Jul',8:'Aug',9:'Sep',10:'Oct',11:'Nov',12:'Dec'} nameToNumber = {} lines = [] with open("C:\RawCallLogs.csv","r") as f: for line in f: fields = line.split(',') folder = fields[0].replace('\"','') if folder == 'Folder': continue number = fields[1].replace('\"','') name = fields[2].replace('\"','') rawtime = fields[3].replace('\"','') structTime = time.strptime(rawtime,'%m/%d/%Y %H:%M:%S') weekday = "Weekday" if (structTime.tm_wday >= 5): weekday = "Weekend" dayName = dayNames[structTime.tm_wday] month = monthNames[structTime.tm_mon] day = structTime.tm_mday year = structTime.tm_year evening = "Daytime" if structTime.tm_hour > 18: evening = "Evening" duration = int(fields[4].replace('\"','').replace('\n',''))/60.0 if number == '-1': name = 'Unknown' if name != "": if name not in nameToNumber: nameToNumber[name] = set([number]) else: nameToNumber[name].add(number) lines.append([folder,number,name,rawtime,duration,weekday,evening,dayName,month,day,year,structTime.tm_hour,structTime.tm_min]) print len(lines) def is08Number(number): return number.startswith('08') or number.startswith('0448') def isLandlineNumber(number): return number.startswith('02') or number.startswith('0442') def isMobile(number): return len(number) > 7 def isInternational(number): return number.startswith('0091') or number.startswith('+91') with open("C:\RawCallLogsOut.csv","w") as f: f.write('Folder,Number,Name,Raw time,Duration,Weekday(s),DayTime,DayofWeek,Month,Day,Year,Hour,Min,NumberType\n') for line in lines: if (line[2] == ''):# No name for name,numbers in nameToNumber.items(): for number in numbers: numberInLine = line[1][::-1][:6][::-1] numberInMap = number[::-1][:6][::-1] if numberInLine == numberInMap: line[2] = name break if (line[2] == ''): if is08Number(line[1]): line[2] = "Unknown 08 Number" elif isLandlineNumber(line[1]): line[2] = 'Unknown landline' elif isMobile(line[1]): line[2] = 'Unknown mobile' else: line[2] = 'Unknown' numberType = 'Unknown' if (is08Number(line[1])): numberType = "08 Number" elif isLandlineNumber(line[1]): numberType = "Landline" elif isInternational(line[1]): numberType = "International" elif isMobile(line[1]): numberType = "Mobile" f.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % (line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],\ line[8],line[9],line[10],line[11],line[12],numberType))
from urllib2 import ProxyHandler, build_opener proxyMap = {'https': 'http://(user):(pass)@(proxyhost):(proxypass)/'} proxy = ProxyHandler(proxyMap) opener = build_opener(proxy) u = opener.open('https://somehttpspage') data = u.read() charset = u.info().getparam('charset') # Python 2 print 'CharSet %s' % charset print '------------------------------------------------------------------------' print data
''' Created on 15 Apr 2010 @author: viswanav ''' import glob, subprocess, os vlcLocation = "C:\Development\Apps\PortableApps\VLCPortable\App\\vlc\\vlc.exe" for g in glob.glob("C:\Development\Docs\Books\VideoCDs\*\PK*"): audioFile = "" for flvGlob in glob.glob(g + "\*\media\*.flv"): audioFile = flvGlob break; convertToMov = ["java","-cp","C:\Development\workspaces\Trials\JavaTrials\JMF\out\production\JMFTrial","JpegImagesToMovie", "-w", "400","-h","300","-f","15",g] #print convertToMov print "Convert to Mov File" subprocess.call(convertToMov) movFileLocation = "" for movFile in glob.glob(g + "\*.mov"): movFileLocation= movFile break stdoutCommand = "--sout=#transcode{vcodec=mp4v,vb=800,acodec=mp4a,ab=128,scale=1,channels=2,audio-sync}:std{access=file,mux=mp4,dst=\"%s.mp4\"}" % movFileLocation print stdoutCommand addAudioAndConverToMp4Command = [vlcLocation,"-I","dummy",movFileLocation,"--input-slave=\"%s\"" % audioFile,stdoutCommand,"vlc://quit"] print addAudioAndConverToMp4Command print "Creating mp4 file" subprocess.call(addAudioAndConverToMp4Command) deleteMovCommand = ["del",movFileLocation] print deleteMovCommand print "Deleting mov file" os.remove(movFileLocation)
''' Created on 25 Mar 2010 ''' import httplib import os import sys from optparse import OptionParser import time, thread from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter, A4 from reportlab.lib.units import cm, mm, inch, pica write = sys.stdout.write h = httplib.HTTPConnection('webproxy',8080) headers = {'Cookie':''} size = 1800 urltemplate = ' /%s/pages/%i.jpg?width=1800' books = ('isbn2','isbn1') maxPages = 10000 def downloadBookImages(folderLocation,isbn): bookLocation = folderLocation + "\\%s" % isbn print 'Downloading book to %s' % bookLocation #Check if the folder location exists if os.path.exists(bookLocation) == False: os.mkdir(bookLocation) # If not create the folder h = httplib.HTTPConnection('webproxy',8080) imageFilePathTemplate = bookLocation + "\\%i.jpg" # Loop through all the pages for the book and save the page for page in range(maxPages): # Create the image file path imageFilePath = imageFilePathTemplate % page; # Check if the file exists if os.path.exists(imageFilePath) == True: write('E%i ' % page) continue url = urltemplate % (isbn,page) h.request('GET', url,headers=headers) write('.') responce = h.getresponse() if responce.status == 401: print 'Not Authorized Book %s, the cookie has expired' % isbn break; data = responce.read() if len(data) < 1000: print 'End of book %s since the page size is too small : %i' % (isbn,len(data)) break f = open(imageFilePath,'wb') f.write(data) f.close() def pdfDirectory(outputPDFName, imageDirectory ): dirim = str(imageDirectory) output = str(outputPDFName) print 'Converting to pdf %s, images %s' % (output,dirim) width, height = A4 height, width = A4 c = canvas.Canvas(output, pagesize=A4) for root, dirs, files in os.walk(dirim): nopage = len(files) for name in range(nopage): #print name/nopage write('.') name = str(name) + ".jpg" filepath = os.path.join(root, name) #if filepath.endswith('20.jpg'): break c.drawImage(filepath, mm * 0.001 , mm * 0.001, height, width, preserveAspectRatio=False) ##c.showPage() c.save() print "PDF of Image directory created %s" % outputPDFName def threadExe(location,isbn): print 'Executing Thread for location %s book %s\n' % (location,isbn) for page in range(maxPages): print '%s Page - %i \n' % (isbn,page) time.sleep(10) def createOptionParser(): parser = OptionParser(usage="Usage: %prog [options]", version="%prog 1.0") parser.add_option("-i", "--isbn", dest="isbn", action='store', type='string') parser.add_option("-d", action="store_true", dest="download", help="Download the book images", default=False) parser.add_option("-c", action="store_true", dest="converToPdf", help="Convert images to pdf file", default=False) parser.add_option("-f", "--imageFolder", type="string", help="Image folder to download or to read from.") parser.add_option("-p", "--pdfOutputFolder", type="string", help="Pdf output folder.") return parser if __name__ == '__main__': parser = createOptionParser() (options, args) = parser.parse_args() if not options.isbn: parser.error("You have to specify the isbn book number") if options.download or options.converToPdf: if not options.imageFolder: parser.error("Specify the image folder") if options.download: downloadBookImages(options.imageFolder,options.isbn) if options.converToPdf: if not options.pdfOutputFolder: parser.error("Specify the pdf folder") print 'Converting to pdf %s, images %s' % (options.pdfOutputFolder,options.imageFolder) pdfDirectory(options.pdfOutputFolder + options.isbn + ".pdf" , options.imageFolder) else: print 'Specify if you would like to download or convert the book or both?' # # for book in books: # downloadBookImages('c:\\tmp',book) # # for book in books: # pdfDirectory('w:\\%s' % book , 'c:\\tmp\\%s.pdf' % book) #
$ffmpeg -i input.flv -f flv -vn -acodec copy output.flv
$find . -name *.flv -exec cp '{}' '{}'.`date +%d.%m.%y`.original \; -exec ffmpeg -i '{}' -y -f flv -vn -acodec copy '{}' \;
$find . -name *.flv -exec cp '{}' '{}'.original \; -exec ffmpeg -i '{}'.original -y -f flv -vn -acodec copy '{}' \;
package bookextracter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import javax.imageio.stream.FileImageOutputStream; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.itextpdf.text.BadElementException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.pdf.PdfWriter; /** * Library Dependencies * iText (http://itextpdf.com/index.php) * Used for creating pdf documents. * Some really good example code using iText (http://www.roseindia.net/java/itext/index.shtml) * * Apache Commons Logger (http://commons.apache.org/logging/) * A generic interface for logging. * * The high level steps are as follows * 1. Log into the online book site using your browser * 2. Use an HTTP monitor (something like httpfox for firefox) to introspect the request/response messages * 3. As your are browsing through the online book pages note the cookie headers in the GET request for each page. Note down this cookie string * since you will be using it in this program * * */ public class Main { static Log _logger = LogFactory.getLog(Main.class); /** * The cookie that is unique to my login. */ public static final String cookie = "not real cookie"; /** * Each pages is a jpg image and this determines the scaling factor when we make a request from the server. */ public static final int MAX_SCALE = 1200; /** * I loop through these many number of pages till reach the end or the server responses with code '500' * Here I assume that all the books contain a max of 1500 pages. */ public static final int MAX_ESTIMATE_BOOK_SIZE_IN_PGS = 1500; public static final String bookSaveLocation = "C:\\Extract\\Books\\"; public static final String rawImageSaveLocation = "C:\\Extract\\RawImages\\"; public static void main(String[] args) throws HttpException, IOException, DocumentException, InterruptedException { // These are the ISBN numbers of the books that I am interested in.(not real) String[] bookIsbs = { "234234234", "1234234234", "234234234"}; // loop through each book and fetch all the pages for each book in a different thread. for (String isbn : bookIsbs) { (new Thread(new BookFetcher(isbn))).start(); } // Wait for it. System.in.read(); } private static class BookFetcher implements Runnable { private String isbn; public BookFetcher(String isbn) { this.isbn = isbn; } @Override public void run() { try { extractAndSaveBook(isbn); } catch (Exception e) { _logger.error(e); e.printStackTrace(); } } } private static void extractAndSaveBook(String isbn) throws IOException, HttpException, FileNotFoundException, DocumentException { // The format of the pdf doc. Document pdfDoc = new Document(PageSize.A2, 0, 0, 0, 0); // Document pdfDoc = new Document(PageSize.LETTER,0,0,0,0); // Document pdfDoc = new Document(); // The file name and location of the pdf file final String pdfFileName = bookSaveLocation + isbn + ".pdf"; PdfWriter.getInstance(pdfDoc, new FileOutputStream(pdfFileName)); pdfDoc.open(); // Set up the http Connection _logger.debug("Creating an Http Client"); HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setProxy("webproxy", 80); // I use a proxy. _logger.info("Retriving Book " + isbn); // Loop through each page. for (int currentPageNumber = 0; currentPageNumber < MAX_ESTIMATE_BOOK_SIZE_IN_PGS; currentPageNumber++) { // Create the page url String pageUrl = construcPageUrl(isbn, currentPageNumber, MAX_SCALE); _logger.debug("Retrive Page: " + pageUrl); // Print the page number do indicate progress. System.out.print(currentPageNumber + ".."); if ((currentPageNumber + 1) % 30 == 0) System.out.println(""); // The retrived image for each page will be saved at the following location (file format: <rawImageSaveLocation>/<isbn>/Page_<currentPageNo>.jpg String pagePathName = rawImageSaveLocation + isbn + "\\Page_" + currentPageNumber + ".jpg"; File imageFile = new File(pagePathName); // If the file dosent exist at the location the fetch the file from the server. // This prevents us from hitting the server during multiple runs, since fetching // each page is the most time consuming operation. if (!(imageFile.exists() && imageFile.isFile())) { GetMethod getPage = new GetMethod(pageUrl); getPage.setRequestHeader("Cookie", cookie); // Setup the http GET request with my cookie int responseCode = httpClient.executeMethod(getPage); if (responseCode != 200) { _logger.info("Page Not found, I assume we are done with the book"); break; } // Get the data _logger.debug("Get the Page"); byte[] pageRawByteArray = getPage.getResponseBody(); // Save the Raw Image to file saveRawImageToFile(pagePathName, pageRawByteArray); } // Save the image page to pdf. savePageImageToPdfDoc(pdfDoc, pdfFileName, pagePathName); } System.out.println(""); _logger.info("Book " + isbn + " ....Done"); pdfDoc.close(); } private static void savePageImageToPdfDoc(Document pdfDoc, final String pdfFileName, String pagePathName) throws BadElementException, MalformedURLException, IOException, DocumentException { _logger.debug("Saving to pdf Doc " + pdfFileName); // Image pagePdfImage = Image.getInstance(pageRawByteArray); Image pagePdfImage = Image.getInstance(pagePathName); // pagePdfImage.scalePercent(50); pdfDoc.add(pagePdfImage); } private static void saveRawImageToFile(String pagePathName, byte[] pageRawByteArray) throws FileNotFoundException, IOException { _logger.debug("Saving Image to a file : " + pagePathName); FileImageOutputStream imageWriter = new FileImageOutputStream( new File(pagePathName)); imageWriter.write(pageRawByteArray); imageWriter.close(); } private static String construcPageUrl(String bookIsbn, int pageNo, int scale) { return "http://booksitehostname/" + bookIsbn + " + scale + "/" + pageNo + ".jpg"; } }