extract

How to extract metadata from a image using python?

旧城冷巷雨未停 提交于 2019-11-30 07:02:13
Hi im working on a program that will open an image and then extract the metadata from it How do i extract metadata using python ? Thanks Use Pillow , it's a fork of PIL that is still in active development, and supports python3. Here I use a dict generator to map the exif data to a dict from PIL import Image, ExifTags img = Image.open("/path/to/file.jpg") exif = { ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS } You can use following python code for this. #!/bin/python import os import sys from PIL import Image from PIL.ExifTags import TAGS image = sys.argv[1] for

Extract separate non-zero blocks from array

核能气质少年 提交于 2019-11-30 07:01:30
问题 having an array like this for example: [1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1] What's the fastest way in Python to get the non-zero elements organized in a list where each element contains the indexes of blocks of continuous non-zero values? Here the result would be a list containing many arrays: ([0, 1, 2, 3], [9, 10, 11], [14, 15], [20, 21]) 回答1: >>> L = [1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1] >>> import itertools >>> import operator >>>

Pdfminer python 3.5

左心房为你撑大大i 提交于 2019-11-30 06:54:34
问题 I have followed a few tutorials around but I am not able to get this code block to run, I did the necessary switches from StringIO to BytesIO (I believe?) I am unsure why 'banana' is printing nothing, I think the errors might be red herrings? is it something to do with me following a python2.7 tutorial and trying to translate it to python3? errors: File "/Users/foo/PycharmProjects/Try/Pdfminer.py", line 28, in <module> banana = convert("A1.pdf") File "/Users/foo/PycharmProjects/Try/Pdfminer

Extract the text out of HTML string using JavaScript

穿精又带淫゛_ 提交于 2019-11-30 05:06:50
I am trying to get the inner text of HTML string, using a JS function(the string is passed as an argument). Here is the code: function extractContent(value) { var content_holder = ""; for(var i=0;i<value.length;i++) { if(value.charAt(i) === '>') { continue; while(value.charAt(i) != '<') { content_holder += value.charAt(i); } } } console.log(content_holder); } extractContent("<p>Hello</p><a href='http://w3c.org'>W3C</a>"); The problem is that nothing gets printed on the console( content_holder stays empty). I think the problem is caused by the "===" operator.. Rick Hitchcock Create an element,

REGEX in R: extracting words from a string

[亡魂溺海] 提交于 2019-11-30 05:03:17
问题 i guess this is a common problem, and i found quite a lot of webpages, including some from SO, but i failed to understand how to implement it. I am new to REGEX, and I'd like to use it in R to extract the first few words from a sentence. for example, if my sentence is z = "I love stack overflow it is such a cool site" id like to have my output as being (if i need the first four words) [1] "I love stack overflow" or (if i need the last four words) [1] "such a cool site" of course, the

stax - get xml node as string

。_饼干妹妹 提交于 2019-11-30 04:48:28
问题 xml looks like so: <statements> <statement account="123"> ...stuff... </statement> <statement account="456"> ...stuff... </statement> </statements> I'm using stax to process one " <statement> " at a time and I got that working. I need to get that entire statement node as a string so I can create "123.xml" and "456.xml" or maybe even load it into a database table indexed by account. using this approach: http://www.devx.com/Java/Article/30298/1954 I'm looking to do something like this: String

Extract Audio from FLV stream in C#

☆樱花仙子☆ 提交于 2019-11-30 04:07:09
I'd like to extract audio stream from a FLV stream in C#. I searched in Google and I found FLVExtract , but it supports only extracting from FLV files, and not from streams. How can I do this? I didn't find anything, so I had to write it myself. It is very fast and it's working great. Here's the code: protected byte[] ExtractAudio(Stream stream) { var reader = new BinaryReader(stream); // Is stream a Flash Video stream if (reader.ReadChar() != 'F' || reader.ReadChar() != 'L' || reader.ReadChar() != 'V') throw new IOException("The file is not a FLV file."); // Is audio stream exists in the

How to use jq to find all paths to a certain key

主宰稳场 提交于 2019-11-30 04:05:19
问题 In a very large nested json structure I'm trying to find all of the paths that end in a key. ex: { "A": { "A1": { "foo": { "_": "_" } }, "A2": { "_": "_" } }, "B": { "B1": {} }, "foo": { "_": "_" } } would print something along the lines of: ["A","A1","foo"], ["foo"] Unfortunately I don't know at what level of nesting the keys will appear, so I haven't been able to figure it out with a simple select. I've gotten close with jq '[paths] | .[] | select(contains(["foo"]))' , but the output

C/C++ Code to treat a character array as a bitstream

亡梦爱人 提交于 2019-11-30 02:28:25
I have a big lump of binary data in a char[] array which I need to interpret as an array of packed 6-bit values. I could sit down and write some code to do this but I'm thinking there has to be a good extant class or function somebody has written already. What I need is something like: int get_bits(char* data, unsigned bitOffset, unsigned numBits); so I could get the 7th 6-bit character in the data by calling: const unsigned BITSIZE = 6; char ch = static_cast<char>(get_bits(data, 7 * BITSIZE, BITSIZE)); This may not work for sizes greater than 8, depending on endian system. It's basically what

How to extract the first and final words from a string?

旧时模样 提交于 2019-11-30 01:20:39
问题 I have a small problem with something I need to do in school... My task is the get a raw input string from a user ( text = raw_input() ) and I need to print the first and final words of that string. Can someone help me with that? I have been looking for an answer all day... 回答1: You have to firstly convert the string to list of words using str.split and then you may access it like: >>> my_str = "Hello SO user, How are you" >>> word_list = my_str.split() # list of words # first word v v last