Repository
<p dir="auto"><span><a href="https://github.com/to-the-sun/amanuensis" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/to-the-sun/amanuensis
<p dir="auto"><br />
<a href="https://steemit.com/utopian-io/@to-the-sun/create-a-python-script-that-periodically-appends-log-entries-to-a-text-file-a-test-request-for-the-open-source-project-the" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Link to Task Request<span>This development contribution is submitted in association with task request by <a href="/@to-the-sun">@to-the-sun:
<h2>What is Amanuensis?
<p dir="auto"><span>The Amanuensis is an automated songwriting and recording system created by <a href="/@to-the-sun">@to-the-sun aimed at ridding the process of anything left-brained, so one need never leave a creative, spontaneous and improvisational state of mind, from the inception of the song until its final master. The program will construct a cohesive song structure, using the best of what you give it, looping around you and growing in real-time as you play. All you have to do is jam and fully written songs will flow out behind you wherever you go.
<h3>New Feature
<h4>The Logger Script
<p dir="auto">I created a python script for logging the messages sent from the main application using UDP, which is written to a text file by the script.<br />
There are two types of logs,
<ul>
<li>A default log created in the app directory.
<li>A project-specific log that gets created once a project is opened. The location of the log file is determined by a message mentioning the <code>projectPath
<p dir="auto">The <code>projectPath message was parsed and the path was extracted and handled OS independently by using python's <strong>Pathlib library. So in future, even if the supporting platforms are changed the path strings will be handled seamlessly.
<p dir="auto">I also had to create a thread for implementing a timeout. This was to roll back to the default log file on 30 seconds of inactivity (Not receiving any messages from the app) as required by the Project owner.
<h4>Implementation
<p dir="auto"><span>The script file: <a href="https://github.com/to-the-sun/amanuensis/blob/master/logger.py" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/to-the-sun/amanuensis/blob/master/logger.py
<p dir="auto">To implement the timeout, a variable was set to 30, which gets decremented every second in a thread. On arrival of a message, it is reset to 30 again.
<h5>Relevant Codes
<p dir="auto">UDP Socket
<pre><code>logger = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
logger.bind(("127.0.0.1", 10247))
<p dir="auto">Function to receive the message
<pre><code>def receiveMessage(self):
"""
Receives a message from the socket and writes to the file.
The counter is reset on each call.
Returns the message as an array of strings.
"""
message = bytes.decode(logger.recv(99999))
if self.defaultReceiveMode:
self.setReceiveDefaultMode(False)
return self.defaultReceive(message)
else:
self.resetCounter()
print(message)
self.log_file.write(message + "\n")
return message.split(' ')
<p dir="auto">Thread to check timeout:
<pre><code>def check_timeout():
"""
Thread to check if a timeout has occurred.
Log directory is changed to default on timeout.
Helps in closing the file every 30 seconds to update it.
"""
while True:
if not log.counterTimedOut():
time.sleep(1)
log.counter -= 1
else:
log.resetCounter()
if not log.pathIsDefault():
log.closeLog()
log.setReceiveDefaultMode(True)
else:
log.changeProjectPath(defaultPath)
<p dir="auto"><br /><br />
Function to change log directory:
<pre><code>def changeProjectPath(self, newPath):
"""
Change the log directory to specified newPath, and create a new log file.
Returns the new projectPath
"""
if newPath == defaultPath:
self.closeLog()
if self.pathIsDefault():
self.log_file = self.projectPath.open('a')
else:
self.log_file = newPath.open('w')
elif not newPath == self.projectPath:
self.closeLog()
copyfile(str(self.projectPath), str(newPath))
self.log_file = newPath.open('a')
self.projectPath = newPath
return self.projectPath
<h4>GitHub Account
<p dir="auto"><span><a href="https://github.com/ajmaln" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/ajmaln
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!Hey @ajmaln
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.Congratulations! This post has been upvoted from the communal account, @minnowsupport, by ajmaln from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the
If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.
Congratulations @ajmaln! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :
<p dir="auto"><a href="http://steemitboard.com/@ajmaln" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link"><img src="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/posts.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/posts.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/posts.png 2x" /> Award for the number of posts published <p dir="auto"><sub><em>Click on the badge to view your Board of Honor.<br /> <sub><em>If you no longer want to receive notifications, reply to this comment with the word <code>STOP <p dir="auto">To support your work, I also upvoted your post! <p dir="auto"><strong><span>Do not miss the last post from <a href="/@steemitboard">@steemitboard:<br /> <a href="https://steemit.com/steemitboard/@steemitboard/steemitboard-world-cup-contest-france-vs-belgium" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">SteemitBoard World Cup Contest - France vs Belgium <hr /> <p dir="auto"><strong>Participate in the <a href="https://steemit.com/steemitboard/@steemitboard/steemitboard-world-cup-contest-collect-badges-and-win-free-sbd" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">SteemitBoard World Cup Contest!<br /> Collect World Cup badges and win free SBD<br /> Support the Gold Sponsors of the contest: <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=good-karma&approve=1" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">@good-karma and <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=lukestokes.mhth&approve=1" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">@lukestokes <hr /> <blockquote> <p dir="auto">Do you like <a href="https://steemit.com/@steemitboard" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">SteemitBoard's project? Then <strong><a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Vote for its witness and <strong>get one more award!Just want to say working with @ajmaln was a breeze and I'm looking forward to the possibility of doing it again. He was professional, skilled, knew exactly what I was asking for and prompt. A credit to the utopian ecosystem!
Thank you for your kind words @to-the-sun. Looking forward to working with you again.
Congratulations! This post has been chosen as one of the daily Whistle Stops for The STEEM Engine!
You can see your post's place along the track here: The Daily Whistle Stops, Issue 193 (7/12/18)
The STEEM Engine is an initiative dedicated to promoting meaningful engagement across Steemit. Find out more about us and join us today.