Is there a way to copy Google Earth place names as text? - compare

I'm new to python and doing a work project that involves juggling a lot (5-10k) of "places" (polygons representing regions) in google earth. As such, I wanted to run a list compare between the places I have in google earth against a txt file list of places I should have. The only problem is that I cannot seem to find a way to copy paste or otherwise capture the name text of the google earth places. Copying with control c or right click copy copies them as a KMZ file, or when pasted into a text editor gives the full source from their "properties" tab. I'm fairly confident in manipulating and comparing the lists once I have the data in that format, but could really use some help in attaining it as such.

First right-click on saved places in Google Earth and save as KML (text) file.
Next, you can use Python to extract the place names from the KML file.
Here's some sample code using pykml module to parse out the place names.
from pykml import parser
with open('places.kml') as f:
root = parser.parse(f).getroot()
# iterate over each placemark
for pm in root.Document.Placemark:
name = pm.name.text
print(name)

Related

Read-in df from csv before launching main app | Dash

I am trying to get my first dashboard with python dash running.
The whole thing is very similar to this https://github.com/dkrizman/dash-manufacture-spc-dashboard.
At the beginning a Dataframe is read in from a csv. My problem seems to be quite easy to solve but somehow I am not succeeding:
I want to create a initial window that allows the user to select (from e.g. dropdown) the csv file (or accordingly the path) that is read in. All the .csv files look the same but just have different values.
When using the modal components I get problems with the install of bootstrap and I thought there must be an easier way?
Thanks for your help!
Best,
Nik

Grabbing Text from Sublime Text Regions

I'm new to creating Sublime Text 3 Plugins and I'm trying to understand the Plugin API that's offered. I want to be able to "grab" text I highlight with my mouse and move it somewhere else. Is there a way I can do this using the Sublime Text Plugin API?
So far, all I've done is be able to create a whole region:
allcontent = sublime.Region(0, self.view.size())
I've tried to grab all of the text in the region and put it into a lot file:
logfile = open("logfile.txt", "w")
logfile.write(allcontent)
But unsuccessfully of course as the log file is blank after it runs.
I've looked over google and there is not a lot of documentation, except for the unofficial documentation, in which I can't find a way to grab the text. Nor are there many tutorials on this.
Any help is greatly appreciated!
A Region just represents a region of text (i.e. from position 0 to position 10), and isn't tied to any specific view.
To get the underlying text from the view's buffer, you need to call the view.substr method with the region as a parameter.
import os
logpath = os.path.join(sublime.cache_path(), 'logfile.txt')
allcontent = self.view.substr(sublime.Region(0, self.view.size()))
with open(logpath, 'w') as logfile:
logfile.write(allcontent)
print('written buffer contents to', logpath)
To get the region represented by the first selection, you can use self.view.sel()[0] in place of sublime.Region(0, self.view.size()).

Python in Knime: Downloading files and dynamically pressing them into workflow

I'm using Knime 3.1.2 on OSX and Linux for OPENMS analysis (Mass Spectrometry).
Currently, it uses static filename.mzML files manually put in a directory. It usually has more than one file pressed in at a time ('Input FileS' module not 'Input File' module) using a ZipLoopStart.
I want these files to be downloaded dynamically and then pressed into the workflow...but I'm not sure the best way to do that.
Currently, I have a Python script that downloads .gz files (from AWS S3) and then unzips them. I already have variations that can unzip the files into memory using StringIO (and maybe pass them into the workflow from there as data??).
It can also download them to a directory...which maybe can them be used as the source? But I don't know how to tell the ZipLoop to wait and check the directory after the python script is run.
I also could have the python script run as a separate entity (outside of knime) and then, once the directory is populated, call knime...HOWEVER there will always be a different number of files (maybe 1, maybe three)...and I don't know how to make the 'Input Files' knime node to handle an unknown number of input files.
I hope this makes sense.
Thanks!
Thanks to Gábor for getting me on the right track. Although I ended up doing a slightly different route after much experimentation.
===
Being new to Knime, I don't know if this is an efficient use of Knime, or a complete Kluge...but it does work.
So, part of the problem is some of the Knime specific objects - One of which is called URIDataValue.
A Python Pandas dataframe is, apparently, interchangable with the Knime tables. However, I don't know if there's a way to import one of these URIDataValue objects into Python. So here's what I did...
1. I wrote a Python script that creates a Pandas Dataframe, and populates it with one Column. Everything is a string, including the column header:
from pandas import DataFrame
# Create empty table
T = DataFrame(
[
['file:///Users/.../copy/lfq_spikein_dilution_1.mzML'],
['file:///Users/.../copy/lfq_spikein_dilution_2.mzML'],
],
)
T.columns = ['URIDataValue']
#print T
output_table = T
That creates this dataframe:
Note: The column name and values are just strings. But it is (apparently) important that the column header be 'URIDataValue'...even though HERE it's just text. If the column name is not 'URIDataValue' the next node doesn't know what to do.
NEXT, the 'output_table' from the 'Python Source' node is patched to a 'String to URI' node, which (apparently and magically) knows to change the entire columns string values to URIDataValues (presumably based on the name of the first column...don't know that for sure).
Finally, the NEW table, with the correct data objects goes to a 'URI to PORT' node...since apparently 'Port' objects and a 'URI' object are different.
This, then, matches the needed input to the ZipLoop...which is normally the out put from a static (hard coded) 'Input Files' node.
Now, to actually solve the question above, I just have to add the code to my 'Python Source' to download and unzip the S3 files, then annotate the dataframe with their locations, and go.
I have no idea what I'm doing, but it worked.
There are multiple options to let things work:
Convert the files in-memory to a Binary Object cells using Python, later you can use that in KNIME. (This one, I am not sure is supported, but as I remember it was demoed in one of the last KNIME gatherings.)
Save the files to a temporary folder (Create Temp Dir) using Python and connect the Pyhon node using a flow variable connection to a file reader node in KNIME (which should work in a loop: List Files, check the Iterate List of Files metanode).
Maybe there is already S3 Remote File Handling support in KNIME, so you can do the downloading, unzipping within KNIME. (Not that I know of, but it would be nice.)
I would go with option 2, but I am not so familiar with Python, so for you, probably option 1 is the best. (In case option 3 is supported, that is the best in my opinion.)

How to edit text file data with c++

I have a program that create a text file of stock items, which contains detail of 'total production' , 'stock remaining' and so on. Now my question is how do I edit that text file with my program. For example if I mistake to enter a correct data (like production was 500 pieces but enter only 400) now how can I edit my file to make it correct without effecting other data.
You probably should not create a text file in the first place. Did you consider using sqlite (or indexed files à la GDBM ...) or some real database like PostgreSQL or MongoDb?
If you insist on editing programmatically a textual file, the only way is to process every line : either keep all of them in memory, or copy them (except the one you'll change) to some new file.... But there is no portable way to change the content of a file in the middle.
You might also be interested in textual serialization formats like JSON, YAML (or maybe even XML).

Is there anyway to rename the "Source" button to something like "HTML"?

Is there anyway to rename the "Source" button to something like "HTML", I ask this as users are confused at how to add html code using the editor?
Yes, inside of the "lang" folder you will see all of the various language files.
For my case, and probably yours, You will want to edit the file "en.js". The file is "compressed" to some degree so it may be difficult to read, but it's still not too difficult to change one string. If you do plan on changing multiple strings you will most likely want to use a service to format Javascript.
Search for the following segment of code. It was one of the very last lines in the file.
"sourcearea":{"toolbar":"Source"}
change it to
"sourcearea":{"toolbar":"HTML"}
Avoid This Method Unless Required
And as for a very unsuggested method, since you can't modify the language files for some reason, you can modify the ckeditor.js file and force a specific label.
Inside of "ckeditor.js" change the line below
a.ui.addButton("Source",{label:a.lang.sourcearea.toolbar,command:"source",toolbar:"mode,10"});
to the follow code
a.ui.addButton("Source",{label:"HTML",command:"source",toolbar:"mode,10"});
The only thing modified is the "label" value in the above line. We remove the reference to the a.language.sourcearea.toolbar and insert a string in it's place instead.