def test_write_to_location(self): test_path = reduce(os.path.join, [ConfigHandler.getPath(), 'test', 'TestInfo']) self.assertTrue(os.path.exists(test_path)) junk_location = os.path.join(test_path, 'junk.txt') DataWriter.writeDataToFile(data='myjunk', location=junk_location) file_opened = open(junk_location, 'r') self.assertEquals('myjunk', file_opened.read()) file_opened.close() os.remove(junk_location)
def test_write_to_directory_that_dne(self): test_path = reduce(os.path.join, [ConfigHandler.getPath(), 'test', 'TestInfo']) test_path_2 = os.path.join(test_path, 'NewPathThatDNE') junk_location_2 = os.path.join(test_path_2, 'junk.txt') DataWriter.writeDataToFile(data='myjunk', location=junk_location_2) file_opened = open(junk_location_2, 'r') self.assertEquals('myjunk', file_opened.read()) file_opened.close() os.remove(junk_location_2) os.rmdir(test_path_2)
def main(): while 1: print "Starting up connection" reader = Communicator("/dev/ttyS1", 9600, 30) reader.setDaemon(True) reader.start() writer = DataWriter.DatabaseWriter() while threading.active_count() > 0: time.sleep(5) if reader.IsValid(): #Save our data off to the database if we've had an update #TODO: Change this so that instead of just taking this time as our value, #we only update the updated time on the ArduinoState whenever the primary temperature got a new value. #Then we can use that value to update our database x = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f') writer.writeData([ x, reader.m_ArduinoState.m_PrimaryTemperature, reader.m_ArduinoState.m_HeatingState, reader.m_ArduinoState.m_CoolingState ]) print reader.ToString() print "All done"
async def on_ready(): await bot.change_presence(status=discord.Status.online, activity=discord.Game('Made by Shep and Peter!')) print(f'Logged in as: {bot.user.name}') print(f'With ID: {bot.user.id}') @bot.event async def on_command_completion(ctx): global command_impact command_impact += 1 def get_impact(): global command_impact return command_impact bot.add_cog(settings.Settings(bot)) bot.add_cog(calculate.Calculate(bot)) bot.add_cog(results.Results(bot)) bot.add_cog(CommandErrorHandler.CommandErrorHandler(bot)) bot.add_cog(info.Info(bot)) bot.add_cog(DataSender.DataSender(bot, guild_id)) bot.add_cog(DataWriter.DataWriter(bot)) bot.add_cog(MatchMaker.MatchMaker(bot)) bot.add_cog(help_functions.Impact(bot)) if "BOT_TOKEN" in os.environ.keys(): print("Starting bot...") bot.run(os.environ['BOT_TOKEN']) else: print(os.environ.keys()) with open('work_bot_token.txt', 'r') as f: bot.run(f.read().strip())
import DataWriter import datetime DataWriter.updatePricesToDB(1, datetime.datetime(2014, 1, 1), datetime.datetime(2016, 11, 27)) print "finish"
def test_root_fails(self): test_path = os.path.join('', '/') result = DataWriter.writeDataToFile(data='myjunk', location=test_path) self.assertFalse(result)
def test_null_location_does_not_write(self): test_path = '' result = DataWriter.writeDataToFile(data='myjunk', location=test_path) self.assertFalse(result)
from RecordBuilder import * from DataWriter import * database = RecordBuilder() database.addRecord(name='Rafal', surname='Sikora', adress='Fieldorfa-Nila 200', age=24, heigh=180, salary=2000) database.addRecord(name='Lukasz', surname='Lis', adress='Kukulskiego 23', age=33, heigh=201, salary=4000) database.addRecord(name='Mariusz', surname='Kot', adress='Warszawska 4', age=56, heigh=143, salary=6000) database.addRecord(name='Antoni', surname='Paderewski', adress='Popielata 2', age=12, heigh=120, salary=0) exporter = DataWriter("databaseOutput.txt") exporter.dump(database.content())