Read text from url and convert it to xlsx file with Python
I want to read a text from url and convert it to .xlsx with Python. This is the url for the text: https://podaac-tools.jpl.nasa.gov/drive/files/allData/tellus/L4/ice_mass/RL06/v02/mascon_CRI/antarctica_mass_200204_202202.txt There is a HDR part in the beginning but I only need the values at the end. Not the rows starting with HDR.
do you know?
how many words do you know
See also questions close to this topic
-
Python File Tagging System does not retrieve nested dictionaries in dictionary
I am building a file tagging system using Python. The idea is simple. Given a directory of files (and files within subdirectories), I want to filter them out using a filter input and tag those files with a word or a phrase.
If I got the following contents in my current directory:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
and I execute the following command in the shell:
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
My output will be:
These files were tagged with "World-Building Tool": data/ world_building_budget.txt hello_world.dat world_builder.spec
My current output isn't exactly like this but basically, I am converting all files and files within subdirectories into a single dictionary like this:
def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree
Right now, my dictionary looks like this:
key:''
.In the following function, I am turning the empty values
''
into empty lists (to hold my tags):def empty_str_to_list(d): for k,v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v)
When I run my entire code, this is my output:
hello_world.dat ['World-Building Tool'] world_builder.spec ['World-Building Tool']
But it does not see
data/world_building_budget.txt
. This is the full dictionary:{'data': {'world_building_budget.txt': []}, 'a.txt': [], 'hello_world.dat': [], 'b.exe': [], 'world_builder.spec': []}
This is my full code:
import os, argparse def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree def empty_str_to_list(d): for k, v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v) parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("--filter", action="store", help="keyword to filter files") parser.add_argument("--tag", action="store", help="a tag phrase to attach to a file") parser.add_argument("--get_tagged", action="store", help="retrieve files matching an existing tag") args = parser.parse_args() filter = args.filter tag = args.tag get_tagged = args.get_tagged current_dir = os.getcwd() files_dict = fs_tree_to_dict(current_dir) empty_str_to_list(files_dict) for k, v in files_dict.items(): if filter in k: if v == []: v.append(tag) print(k, v) elif isinstance(v, dict): empty_str_to_list(v) if get_tagged in v: print(k, v)
-
Actaully i am working on a project and in it, it is showing no module name pip_internal plz help me for the same. I am using pycharm(conda interpreter
File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\Scripts\pip.exe\__main__.py", line 4, in <module> File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\__init__.py", line 4, in <module> from pip_internal.utils import _log
I am using pycharm with conda interpreter.
-
Looping the function if the input is not string
I'm new to python (first of all) I have a homework to do a function about checking if an item exists in a dictionary or not.
inventory = {"apple" : 50, "orange" : 50, "pineapple" : 70, "strawberry" : 30} def check_item(): x = input("Enter the fruit's name: ") if not x.isalpha(): print("Error! You need to type the name of the fruit") elif x in inventory: print("Fruit found:", x) print("Inventory available:", inventory[x],"KG") else: print("Fruit not found") check_item()
I want the function to loop again only if the input written is not string. I've tried to type return Under print("Error! You need to type the name of the fruit") but didn't work. Help
-
Please help to find email out of this cipher
Please help me to extract the email from this cipher, i am not been able to identify what type of hash or cipher is this.email is encoded in this hash please help me find the email.
1AAXs0RyFR3OM9nZA3XVkD07AVOZmYUMsRvyeq2BoY42sNbkSUySHCdFdwwQx6LWghNDqiPyBzNE7KDXkerX4vt0klZ2
-
Convert Hexadecimal to Text
I have this hexadecimal value which I am extracting from a serial data reader: 334E5A434A375430313431415556
This hexadecimal value should represent my device serial number, which is either 3QDCJ7W0068SVW or 3Q4CJ7T3A32U9Z.
I tried grouping each 2 consecutive hex values, converted each to a byte, then mapped it to ASCII. But gave me a different output text. I am confident the bits contains no errors as I did compare crc check and it matched what I received.
Any suggestions?
-
Validate user input with data in .txt file
I have searched and searched and tried everything. I am creating a game where the user will input a pre-assigned pin and I want to validate that pin against a .txt file in Python. I have tried so many different lines of code and my result is either everything is valid or nothing is valid. What am I doing wrong? The pins are formatted on each line and are alpha numeric like this...
1DJv3Awv5 1DGw2Eql8 3JGl1Hyt7 2FHs4Etz4 3GDn9Buf8 1CEa9Aty0 2AIt9Dxz9 5DFu0Ati4 3AJu9Byi4 1EAm0Cfn1 3BEr0Gwk0 7JAf8Csf8 4HFu0Dlf4
Here is what I have:
user_input = input('Please enter your PIN: ') if user_input in open("PINs.txt").read(): print('Congratulations! Click the button below to get your Bingo Number.') else: print('The PIN you entered does not match our records. Please check your PIN and try again.')
-
Creating valid XLSX files using SharpZipLib
I am writing a library to work with Excel files. It can generate a valid .xlsx file, except for the zipping up part.
The following code will generate a .ZIP file (as a byte array) that appears to be completely valid. I can unzip it with any .zip tool without a problem.
If, for example, I take a .xlsx file, rename it .zip, and extract all the files to a directory and then zip them up using the code below, rename that from .zip to .xlsx, Excel and LibreOffice will both refuse to open it.
I can, however, unzip that file myself, into a folder and re-zip them up using the OS compression and rename it .xlsx, and it will open just fine. So the contents of the .zip file are fine. The zipping itself is the problem. I've gone through several iterations and this is where it stands and I just can't figure out what I'm missing to satisfy Excel & LibreOffice are expecting. Is there something in the entries that I should be adding to make it a more standard .zip file?
string _rootPath; public byte[] CreateZipFile(string path) { _rootPath = path; using (var ms = new MemoryStream()) using (var zipStream = new ZipOutputStream(ms)) { RecursiveAddToZipFile(zipStream, path); zipStream.Finish(); zipStream.Close(); return ms.ToArray(); } } private void RecursiveAddToZipFile(ZipOutputStream zipStream, string path) { foreach(var dir in Directory.GetDirectories(path)) { var entry = new ZipEntry(dir.Replace(_rootPath, "") + @"/"); RecursiveAddToZipFile(zipStream, dir); zipStream.PutNextEntry(entry); zipStream.CloseEntry(); } var files = Directory.GetFiles(path); foreach(var file in files) { var entry = new ZipEntry(file.Replace(_rootPath, "")); entry.DateTime = DateTime.Now; zipStream.PutNextEntry(entry); using (FileStream fs = File.OpenRead(file)) { int totalBytes = 0; byte[] buffer = new byte[1024 * 32]; int bytesRead; do { bytesRead = fs.Read(buffer, 0, buffer.Length); totalBytes += bytesRead; zipStream.Write(buffer, 0, bytesRead); } while (bytesRead > 0); entry.Size = totalBytes; } zipStream.CloseEntry(); } }
- How to export html to xlxs in angularjs i couldnot able to do it is there any way to do it by adding any libraries?