Hi, this is UNIBA of MJ.
This story is about working with python
in a certain project.
python
is one of the famous languages that needs no special explanation.
I usually work as a front engineer, but I started to touch python
around April, thinking that I want to know the back end recently.
At Universal, I mainly use languages such as javascript
, which is node
, and ruby
, which is rails
, at work.
As a chuunibyo, I chose python
, which no one had done (I regret it because I was in agony because no one could support me).
At that time, at just the right time, there was a project with a backend (I'm really wondering if it's a backend because I didn't set up a server in the end, but ...), so I challenged it. It depends on what I saw.
By the way, I write it quite messy. I don't know
I will look back on what kind of project it was.
html
files when saving photos (folder monitoring + template)The lucky thing about this implementation was that it didn't include a server-side implementation.
I was very fortunate that I didn't have to think about infrastructure development in addition to DB and so on. Or rather, I was pretty worried (no one in the company runs a server with python
!!!).
Let's look back one by one.
html
files when saving photos (folder monitoring + template)Watchdog
to monitor folders, jinja2
to generate html
I used / dev /).
Both are fairly easy-to-use libraries. It's a well-made library that doesn't need any special explanation.
This made the main script a lot easier.
When it comes to using the watchdog
, some of the contents of the folders you want to monitor (such as the number of files and the number of changes) need to be tested.
There was no particular problem with this project.
Regarding the setting of aws, I was in charge of the part that I usually leave the setting to the back end person in the company.
It's a good memory that I got a little trouble in the contract part when I got the domain with route53
.
s3 cannot be basic authenticated
, but it can be restricted by ʻIP, so the test period was supported there. However, the verification around
SNS share` was a little troublesome, so I want to make it easier next time.
I used boto
for uploading on the python side. It is said that ʻamazonhas officially issued it, but honestly it was hard to read the reference and I could not set the communication timeout well, so I felt a bit painful. In addition, if the bucket name contains
., you have to write something special. I noticed the fact just before the release and got a little cold sweat. If you associate it with a domain, you will have to add
.`, so I want you to pay attention to this on the library side ...
It's a precautionary measure to prevent mischievous downloads when publishing photos.
At first, I implemented it myself, but in the end I used a library called basehash
.
The part that became a little problem was the cooperation with other apps.
As a system, an application made by ʻopenFrameworksis running in addition to
python, and a QR code was generated as a link to the web, but the value generated on the
C ++ side is the
pythonside Do not fit. The algorithm is the same, but it still doesn't fit. The cause is that the hash value is too large for
C ++to handle normally. In short, it was a big int problem. It was said that
pythonwill calculate well as much as there is memory in the specification. I guess this is the reason why
pythonis used in research fields such as universities. After all, the encrypted part hit python from
C ++ and returned the result. ʻIf __name__ =='__main__':
is very useful. happy.
The area around here was sober and difficult. .. ..
For example, if communication is lost, a frame will be generated and a warning such as "Please retry" will be issued.
The warning screen must be displayed in the main thread (an amateur who was initially confused without knowing it), but the upload process called from watchdog
runs in a sub thread due to the nature of the library, so between threads I had to communicate.
To be honest, it was a world unknown to the uncle who usually plays with html
.
The Queue
class solved this problem. We were able to use join
and task_done
to facilitate process stop and go coordination. No, it's convenient.
I used logging
to output the log. To be honest, I want to fill in the log rotation part a little more.
Also, with ʻapplescript`, I made it start automatically at login, but that story is omitted this time.
What I thought when I touched the language python
node
, but I want to praise myself who did not failHow is it?
I hope you will come to work with python
again.
Recommended Posts