Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
writer.py 1.51 KiB
import json
from tokenize import String
class FileWriter(object):
def __init__(self, destination: String, data) -> None:
"""
This class can write a certain data to a specific location.
:param destination: Where to store the data.
:param data: The data to be stored.
"""
self.destination = destination
self.data = data
def as_json_of_list(self) -> None:
"""
This method writes the data as json to the destination.
:return: None
"""
with open(self.destination, 'w+') as outfile:
json.dump(self.data, outfile)
def as_json(self) -> None:
"""
This method writes the data as json to the destination.
:return: None
"""
with open(self.destination, 'w+') as outfile:
json.dump(self.data["results"]["bindings"], outfile)
def as_filtered_json(self) -> None:
"""
This method writes the data as json to the destination.
:return: None
"""
with open(self.destination, 'w+') as outfile:
json.dump(self.data, outfile)
def as_string(self, new_line=False) -> None:
"""
This method writes the data as a string linewise to the destination.
:return: None
"""
with open(self.destination, 'w') as out_file:
for d in self.data:
if new_line:
out_file.write(str(d) + '\n')
else:
out_file.write(str(d))