SlideShare a Scribd company logo
1 of 5
Download to read offline
My code does not work right in that when i run create_file, i am unable to keep adding files to
the same directory as it just replaces the file instead. I tried changing the code to use .post instead
of .put but it only adds some file with random letters and numbers instead of the name of the file
I am trying to add in. The same thing happens when I am trying to add new directories under
another directory. I can also only make a standalone directory after adding a "/" afterward ie.
(python3 edfs.py -mkdir test/) while (python3 edfs.py -mkdir list) does not work. How can I fix
these issues.
Here is my code transcript:
import sys
import json
import requests
import base64
# Firebase URL
firebase_url = "url"
# Function to get the data from Firebase
def get_firebase_data(url):
response = requests.get(url)
data = json.loads(response.text)
return data
# Function to list all files and directories under a given directory
def list_directory(dir_path):
data = get_firebase_data(firebase_url + dir_path + ".json")
if isinstance(data, dict):
for key in data.keys():
if key == "content":
print(dir_path + ": " + data[key])
else:
list_directory(dir_path + "/" + key)
# Function to create a new file with the given content
def create_file(file_path, content):
data = {"content": content}
response = requests.put(firebase_url + file_path + ".json", data=json.dumps(data))
if response.status_code == 200:
print("File created successfully")
elif response.status_code == 400:
print("File already exists")
# Function to create a new directory
def create_directory(dir_path):
data = {dir_path: content}
response = requests.put(firebase_url + dir_path + ".json",data=json.dumps(data))
if response.status_code == 200:
print("Directory created successfully")
elif response.status_code == 400:
print("Directory already exists")
# Function to remove a file or directory
def remove(path):
response = requests.delete(firebase_url + path + ".json")
if response.status_code == 200:
print("File/directory removed successfully")
elif response.status_code == 404:
print("File/directory not found")
# Function to export the file system structure in XML format
def export_xml():
root_data = get_firebase_data(firebase_url + ".json")
print("<root>")
for key in root_data.keys():
print("<" + key + ">")
export_directory(key)
print("</" + key + ">")
print("</root>")
# Function to export a directory and its contents in XML format
def export_directory(dir_path):
data = get_firebase_data(firebase_url + dir_path + ".json")
if isinstance(data, dict):
for key in data.keys():
if key == "content":
content = data[key]
print("<file name='" + dir_path + "'>" + base64.b64encode(content.encode('utf-8')).decode('utf-
8') + "</file>")
else:
print("<directory name='" + key + "'>")
export_directory(dir_path + "/" + key)
print("</directory>")
# Parse the command-line arguments
args = sys.argv
if len(args) < 3:
print("Usage: python3 edfs.py <command> <path> [content]")
exit()
command = args[1]
x= args[2].split('/')
content = x[-1]
del x[-1]
path='/'.join(x)
print(path)
# Use the extracted path and file name as needed
if command == "-create":
if len(args) < 2:
print("Usage: python3 edfs.py -create <path> <content>")
exit()
create_file(path, content)
elif command == "-mkdir":
create_directory(path)
elif command == "-rmdir" or command == "-rm":
remove(path)
elif command == "-ls":
list_directory(path)
elif command == "-export":
export_xml()
else:
print("Invalid command: " + command)
print("Usage: python3 edfs.py <command> <path> [content]")

More Related Content

Similar to My code does not work right in that when i run create_file- i am unabl.pdf

APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
DEEPANSHU GUPTA
 
Pyconie 2012
Pyconie 2012Pyconie 2012
Pyconie 2012
Yaqi Zhao
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
Positive Hack Days
 
12-OO-PHP.pptx
12-OO-PHP.pptx12-OO-PHP.pptx
12-OO-PHP.pptx
rani marri
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
Jano Suchal
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
Colin Su
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
Minu Rajasekaran
 

Similar to My code does not work right in that when i run create_file- i am unabl.pdf (20)

Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
 
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...APPLICATION TO DOCUMENT ALL THE  DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
APPLICATION TO DOCUMENT ALL THE DETAILS OF JAVA CLASSES OF A PROJECT AT ONCE...
 
Pyconie 2012
Pyconie 2012Pyconie 2012
Pyconie 2012
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsing
 
My First Ruby
My First RubyMy First Ruby
My First Ruby
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
 
ABCD firebase
ABCD firebaseABCD firebase
ABCD firebase
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
12-OO-PHP.pptx
12-OO-PHP.pptx12-OO-PHP.pptx
12-OO-PHP.pptx
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframework
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
All you need to know about JavaScript Functions
All you need to know about JavaScript FunctionsAll you need to know about JavaScript Functions
All you need to know about JavaScript Functions
 
File System in Nodejs.pdf
File System in Nodejs.pdfFile System in Nodejs.pdf
File System in Nodejs.pdf
 
C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
 
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for FreeDjango in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
 
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
(C Program to Simulate a UNIX-based filesystem) My goal is to implem.docx
 

More from Robert4vCParsonsn

Mulaple choice- answer all questions- (1 point each) 3- Which of the f.pdf
Mulaple choice- answer all questions- (1 point each) 3- Which of the f.pdfMulaple choice- answer all questions- (1 point each) 3- Which of the f.pdf
Mulaple choice- answer all questions- (1 point each) 3- Which of the f.pdf
Robert4vCParsonsn
 
menu' is very easily copied and is not a good soutce of custained adva.pdf
menu' is very easily copied and is not a good soutce of custained adva.pdfmenu' is very easily copied and is not a good soutce of custained adva.pdf
menu' is very easily copied and is not a good soutce of custained adva.pdf
Robert4vCParsonsn
 

More from Robert4vCParsonsn (20)

Name - Rakib Mia Age - 22 Educational Qualification - Class 7 Professi.pdf
Name - Rakib Mia Age - 22 Educational Qualification - Class 7 Professi.pdfName - Rakib Mia Age - 22 Educational Qualification - Class 7 Professi.pdf
Name - Rakib Mia Age - 22 Educational Qualification - Class 7 Professi.pdf
 
Name of the Project- Implementation of a debit card service (1) List a.pdf
Name of the Project- Implementation of a debit card service (1) List a.pdfName of the Project- Implementation of a debit card service (1) List a.pdf
Name of the Project- Implementation of a debit card service (1) List a.pdf
 
Multicellular organisms with a true nucleus- histone proteins- ester-l.pdf
Multicellular organisms with a true nucleus- histone proteins- ester-l.pdfMulticellular organisms with a true nucleus- histone proteins- ester-l.pdf
Multicellular organisms with a true nucleus- histone proteins- ester-l.pdf
 
Mulaple choice- answer all questions- (1 point each) 3- Which of the f.pdf
Mulaple choice- answer all questions- (1 point each) 3- Which of the f.pdfMulaple choice- answer all questions- (1 point each) 3- Which of the f.pdf
Mulaple choice- answer all questions- (1 point each) 3- Which of the f.pdf
 
Mr Ahmad is a 65-year-old male who was admitted to the medical ward as (1).pdf
Mr Ahmad is a 65-year-old male who was admitted to the medical ward as (1).pdfMr Ahmad is a 65-year-old male who was admitted to the medical ward as (1).pdf
Mr Ahmad is a 65-year-old male who was admitted to the medical ward as (1).pdf
 
Mr Ahmad is a 65-year-old male who was admitted to the medical ward as.pdf
Mr Ahmad is a 65-year-old male who was admitted to the medical ward as.pdfMr Ahmad is a 65-year-old male who was admitted to the medical ward as.pdf
Mr Ahmad is a 65-year-old male who was admitted to the medical ward as.pdf
 
Mr- and Mrs- Kim Soo use a fiscal year ending July 31 as the taxable y.pdf
Mr- and Mrs- Kim Soo use a fiscal year ending July 31 as the taxable y.pdfMr- and Mrs- Kim Soo use a fiscal year ending July 31 as the taxable y.pdf
Mr- and Mrs- Kim Soo use a fiscal year ending July 31 as the taxable y.pdf
 
mother delivers a baby that has neonatal drug withdrawal- When talking.pdf
mother delivers a baby that has neonatal drug withdrawal- When talking.pdfmother delivers a baby that has neonatal drug withdrawal- When talking.pdf
mother delivers a baby that has neonatal drug withdrawal- When talking.pdf
 
Most of the cells in the body carry receptors for the insulin hormone.pdf
Most of the cells in the body carry receptors for the insulin hormone.pdfMost of the cells in the body carry receptors for the insulin hormone.pdf
Most of the cells in the body carry receptors for the insulin hormone.pdf
 
Monty Corp- Inc- had a beginning inventory of 100 units of Product RST (1).pdf
Monty Corp- Inc- had a beginning inventory of 100 units of Product RST (1).pdfMonty Corp- Inc- had a beginning inventory of 100 units of Product RST (1).pdf
Monty Corp- Inc- had a beginning inventory of 100 units of Product RST (1).pdf
 
Modular bilis are used to reduce the number of 80M s when a product co.pdf
Modular bilis are used to reduce the number of 80M s when a product co.pdfModular bilis are used to reduce the number of 80M s when a product co.pdf
Modular bilis are used to reduce the number of 80M s when a product co.pdf
 
Modern corporations have always dominated the U-S- economy--going all.pdf
Modern corporations have always dominated the U-S- economy--going all.pdfModern corporations have always dominated the U-S- economy--going all.pdf
Modern corporations have always dominated the U-S- economy--going all.pdf
 
Missing Node while Printing a Sorted List (C) I have a linked list t.pdf
Missing Node while Printing a Sorted List (C)   I have a linked list t.pdfMissing Node while Printing a Sorted List (C)   I have a linked list t.pdf
Missing Node while Printing a Sorted List (C) I have a linked list t.pdf
 
Mod 8 Network Layer Worksheet IPv4 hosts have a routing table they use.pdf
Mod 8 Network Layer Worksheet IPv4 hosts have a routing table they use.pdfMod 8 Network Layer Worksheet IPv4 hosts have a routing table they use.pdf
Mod 8 Network Layer Worksheet IPv4 hosts have a routing table they use.pdf
 
Mimite Vaso What target market did Applebee's pursue in its recent ove.pdf
Mimite Vaso What target market did Applebee's pursue in its recent ove.pdfMimite Vaso What target market did Applebee's pursue in its recent ove.pdf
Mimite Vaso What target market did Applebee's pursue in its recent ove.pdf
 
Merge(numbers- 0-2-5) is called- Complete the table for leftPos and ri.pdf
Merge(numbers- 0-2-5) is called- Complete the table for leftPos and ri.pdfMerge(numbers- 0-2-5) is called- Complete the table for leftPos and ri.pdf
Merge(numbers- 0-2-5) is called- Complete the table for leftPos and ri.pdf
 
menu' is very easily copied and is not a good soutce of custained adva.pdf
menu' is very easily copied and is not a good soutce of custained adva.pdfmenu' is very easily copied and is not a good soutce of custained adva.pdf
menu' is very easily copied and is not a good soutce of custained adva.pdf
 
Mark all the statements that are correct regarding the image shown bel.pdf
Mark all the statements that are correct regarding the image shown bel.pdfMark all the statements that are correct regarding the image shown bel.pdf
Mark all the statements that are correct regarding the image shown bel.pdf
 
Media literacy is an important 21st-century skill- For this discussion.pdf
Media literacy is an important 21st-century skill- For this discussion.pdfMedia literacy is an important 21st-century skill- For this discussion.pdf
Media literacy is an important 21st-century skill- For this discussion.pdf
 
Mel and Jan own a ranch in Wyoming as joint tenants- If Jan dies from.pdf
Mel and Jan own a ranch in Wyoming as joint tenants-  If Jan dies from.pdfMel and Jan own a ranch in Wyoming as joint tenants-  If Jan dies from.pdf
Mel and Jan own a ranch in Wyoming as joint tenants- If Jan dies from.pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 

My code does not work right in that when i run create_file- i am unabl.pdf

  • 1. My code does not work right in that when i run create_file, i am unable to keep adding files to the same directory as it just replaces the file instead. I tried changing the code to use .post instead of .put but it only adds some file with random letters and numbers instead of the name of the file I am trying to add in. The same thing happens when I am trying to add new directories under another directory. I can also only make a standalone directory after adding a "/" afterward ie. (python3 edfs.py -mkdir test/) while (python3 edfs.py -mkdir list) does not work. How can I fix these issues. Here is my code transcript: import sys import json import requests import base64 # Firebase URL firebase_url = "url" # Function to get the data from Firebase def get_firebase_data(url): response = requests.get(url) data = json.loads(response.text) return data # Function to list all files and directories under a given directory def list_directory(dir_path): data = get_firebase_data(firebase_url + dir_path + ".json") if isinstance(data, dict): for key in data.keys(): if key == "content":
  • 2. print(dir_path + ": " + data[key]) else: list_directory(dir_path + "/" + key) # Function to create a new file with the given content def create_file(file_path, content): data = {"content": content} response = requests.put(firebase_url + file_path + ".json", data=json.dumps(data)) if response.status_code == 200: print("File created successfully") elif response.status_code == 400: print("File already exists") # Function to create a new directory def create_directory(dir_path): data = {dir_path: content} response = requests.put(firebase_url + dir_path + ".json",data=json.dumps(data)) if response.status_code == 200: print("Directory created successfully") elif response.status_code == 400: print("Directory already exists") # Function to remove a file or directory def remove(path): response = requests.delete(firebase_url + path + ".json") if response.status_code == 200:
  • 3. print("File/directory removed successfully") elif response.status_code == 404: print("File/directory not found") # Function to export the file system structure in XML format def export_xml(): root_data = get_firebase_data(firebase_url + ".json") print("<root>") for key in root_data.keys(): print("<" + key + ">") export_directory(key) print("</" + key + ">") print("</root>") # Function to export a directory and its contents in XML format def export_directory(dir_path): data = get_firebase_data(firebase_url + dir_path + ".json") if isinstance(data, dict): for key in data.keys(): if key == "content": content = data[key] print("<file name='" + dir_path + "'>" + base64.b64encode(content.encode('utf-8')).decode('utf- 8') + "</file>") else: print("<directory name='" + key + "'>") export_directory(dir_path + "/" + key)
  • 4. print("</directory>") # Parse the command-line arguments args = sys.argv if len(args) < 3: print("Usage: python3 edfs.py <command> <path> [content]") exit() command = args[1] x= args[2].split('/') content = x[-1] del x[-1] path='/'.join(x) print(path) # Use the extracted path and file name as needed if command == "-create": if len(args) < 2: print("Usage: python3 edfs.py -create <path> <content>") exit() create_file(path, content) elif command == "-mkdir": create_directory(path) elif command == "-rmdir" or command == "-rm": remove(path) elif command == "-ls":
  • 5. list_directory(path) elif command == "-export": export_xml() else: print("Invalid command: " + command) print("Usage: python3 edfs.py <command> <path> [content]")