How to save folium map directly to google drive - google-drive-api

I'm working on a script that will update automatically some folium maps in google drive daily.
I got the whole thing working correctly, locally, without issues, except for one thing: since this will be running automatically on a remote server daily, I don't want to save the created maps in the server first and then upload them to google drive. If possible, I would like to create the maps as some kind of file object in the memory, upload them to google drive, and that's it... without having to create multiple physical map files on the server. Is this possible? If yes, how?
This is my code where, after placing markers and clusters, I save the maps as html files in the file system (this is inside a cycle, as I need to update maps for several cities):
folium.LayerControl().add_to(mymap)
mymap.add_child(MeasureControl())
mymap.render()
mymap.save('leads_'+city+'_'+code+'.html')
Then, for each map, this is the code for saving the html map into google drive (using pydrive):
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'parents': [{'id': 'xxxfolder_idxxx'}]})
file1.SetContentFile('leads_'+city+'_'+code+'.html')
file1.Upload()
As I said, this all works fine, but I don't want to saturate the server file system with map files.
Is there a way to do this without having to first save the map in the local file system?

If you meant to directly save the html file to drive (without saving it to local), then you can try this:
file1 = drive.CreateFile({'parents': [{'id': 'xxxfolder_idxxx'}], 'mimeType': 'text/html', 'name': 'leads_'+city+'_'+code+'.html'})
# access the html string of the object and set it via SetContentString
file1.SetContentString(m.get_root().render())
file1.Upload()
Reference:
https://github.com/python-visualization/folium/issues/781

Related

Is there a way to get the hash for a picture stored in Google Photos without downloading the file?

I am attempting to verify that I have successfully copied a bunch of photos from google photos to onedrive. I can programmatically get the sha1 hash of each file stored in OneDrive but I don't see the same option from the google photos rest api. I would have expected it to be in the metadata: https://developers.google.com/photos/library/reference/rest/v1/mediaItems#MediaMetadata
It also doesn't look like the stored photos are exposed through the Google Drive api, so how do I get the hash?
You can get the MD5 Checksum for the files stored on Google drive with the Drive API.
However, there is no way to get the SHA1 hash for files without downloading them.
Also, there is no way to get either of those with the Google Photos API.
Yes you can without downloading the photos - check rclone (listing as jsons returns the hashes)
https://rclone.org/commands/rclone_lsjson/
https://rclone.org/googlephotos/

Unable to import layer from Google Drive to Google Maps

I'm able to import a KML/KMZ layer hosted on my local drive just fine into Google Maps. No issues. However, when I attempt to host the same layer on Google Drive and import from Google Drive, I get the following error:
The file contains invalid or unsupported data, or the file is too large to parse.
I also notice that the icon of the KML file on drive is not the standard Globe icon (it is a globe when placed on my local drive) - but rather, it looks like:
</>
What is happening here? I need to import from Google Drive so I'd like to figure this out. This also begs the question: if I do end up just adding the data from my local drive, what happens if I remove the KML from my drive? Is the data in Google Maps dependent upon it, or once the KML is added to Google Maps, does that KML now exist independently in the cloud?

Google Earth Pro Automated Import and File Save

Via a script I write a single set of lat/long position information into a CSV file which updates meaningfully for me every 2-3 minutes. I can of course successfully import that file into GE Pro and drop a placemark on the map. Once having done that, I wish to save the map as a JPG. No issues with the manual "version" of what I need to do...
How can I automate the import of the CSV file and automate the saving of the resultant map as well? Each map will overwrite itself (can have same file name). I don't see where google has any command line interface to do something like this...
The final result will be, again, a map with the latest positioned placemark whenever I happen to access the jpg file.
Thank you
(I am aware of the Google Earth Fusion product. Am hoping not to have to go that route as my need is fairly simple, I think)

google maps: How to create static images containing lots of GPS path points

I need to create images of GPS paths on top of google maps satellite information. The ultimate goal is to import those images in a report that is being created in an Excel program that is run through userforms & VBA.
I'm having trouble coming up with a way to automate the generation of these images. Preferably the user would not have to install additional software and there would be a way of automating this process using VBA. I would like to use the Static Google Maps API, but that is limited by the number of characters in an HTML request (2048 as I understand) and my path data is easily going to exceed that length.
Let's assume for now that I have a single KML file with my GPS path data.
Any thoughts on a way to convert large KML path files into static maps image files using VBA? I'm imagining VBA opening a local HTML file with a dynamic google map, uploading the KML file, and somehow capturing and saving a screenshot of the KML data loaded onto the dynamic google map.
FYI I'm locked into using the existing Excel/VBA forms-based program to generate these reports.
(new to this board and relatively new at programming so please let me know if my description is lacking. thanks)

Getting KML layer to work locally (e.g. the Google TooManyMarkers Example)

I have copied all of the files for the Google example http://gmaps-samples-v3.googlecode.com/svn/trunk/toomanymarkers/toomanymarkers.html to my PC, but the KML layer does not appear when I tick the checkbox.
The files I copied are:
functions.js
markers.js
markers.kml
toomanymarkers.html
I have also copied these to http://www.performit.co.uk/misc/maps/toomanymarkers/toomanymarkers.html and it doesn't work there either.
Am I missing something? Do I need to have an environment set up for the files to load?
The KML file must be publicly accessible via the web, so this will not work if you are developing locally. Google accesses and processes the file, returning that data as location, zoom level, markers, polylines, polygons, etc.
What is the actual URL to your KML file? Copy that, and past it into the Search Maps box of GoogleMaps. If it's valid KML, GM will process it and display your KML data.
It appears to be a web server configuration issue. When I try to access http://www.performit.co.uk/misc/maps/toomanymarkers/markers.kml, I get a 500 server error. It appears to me that functions.js tries to access that URL. So, I'd look into that. By comparison, http://gmaps-samples-v3.googlecode.com/svn/trunk/toomanymarkers/toomanymarkers.html happily serves up the KML file.