forked from DedSecInside/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavefile.py
More file actions
34 lines (27 loc) · 869 Bytes
/
Copy pathsavefile.py
File metadata and controls
34 lines (27 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Module that facilitates the saving of data to JSON file.
"""
import json
import time
def saveJson(datatype, data):
"""
Creates json file and stores data as JSON.
Args:
datatype (str): Type of the object being passed.
data (list): List of data elements of type 'datatype' to be saved.
Returns:
(str): Name of file data was saved to.
"""
timestr = time.strftime("%Y%m%d-%H%M%S")
file_name = "TorBot-Export-"+datatype+timestr+".json"
# Json File Creation
with open(file_name, "w+") as f:
# Store data in Json format
output = {datatype: data}
# Dump output to file
json.dump(output, f, indent=2)
print("\nData will be saved with a File Name :", file_name)
return file_name
def getJson(file_name):
with open(file_name,"r") as file:
print(file.read())