On YouTube I found a mind blowing video of Alejandro Magnitopic who easily created a working Telegram Bot communicating with a Python application. This video is the base of the project I would like to present to you in this article and most of the source code is coming from Alejandro. The video you can find here: https://www.youtube.com/watch?v=q9YScw0YBB4. It gives you also the first steps of how creating a Telegram Bot. I do not want to describe it in detail here.
The first task was to get the request Python resources into Amesim to get a easy to use web communication. Therefore I go from my point of view the easiest way. I went to https://pypi.org/project/ and downloaded the sources. After the download I just copied the resource into my Simcenter Amesim Folder (C:\Amesim\v1600\Amesim\sys\python\win64\Lib) like you can see in the picture below. There are some more resources needed to get requests started. The complete list you can find it the header of my code in the attachment.
After I had all the resources to get the Python code running I started using the Simcenter Amesim Simulation Scripting routines to control my simulation project. The Simcenter Amesim simulation is very easy as it is just a spring mass damper system. Using the Simcenter Amesim Help it was very easy to create the code finding the correct references. The code allows me to set a parameter, run the simulation and get a variable for further post processing.
And that’s it! My Telegram Amesim Bot Python script is ready. There are just some stumbling blocks in the way you have to move to the side:
Now I just have to open my Simcenter Amesim Model and start the Python command interpreter and give following command:
If the script started without any error you can use your Telegram App to control your Simcenter Amesim model. The picture below shows the possible commands. You will also see some feedback in the Python command interpreter.
So I hope you will enjoy your new simulation possibilities using Telegram Bot and Simcenter Amesim with Python scripting!
Solved! Go to Solution.
Tried it and it does work nicely (not on VPN).
Being a Python novice, I only struggled to extract the packages properly, this is how it should look like.
Okay there's probably too many folders I left in there, but it does work.
Thanks for validating the code. I also faced the same issue that is not working under some circumstances like VPN connection.
Regarding the Python packages I am also a novice. For me it worked also only copying the “request” folder which is highlighted in the picture below. The other folders like .egg-info, tests and the other files are not necessary.
Maybe there is a Python expert in the forum who can explain it to us.
The link in the first message to the pypi.org requests page is not working.
I assume you want to install following package: https://pypi.org/project/requests/
The recommended tool to install python packages is called pip: https://en.wikipedia.org/wiki/Pip_(package_manager)
This tool is often already delivered with the python installation (as is the case from Simcenter Amesim 16, earlier releases this needed to be installed first)
so the method to install the request package:
this installs the package without manual copy pasting.
thanks for your explanation. I really like to learn something new on a Friday afternoon. What I like is, that you do not have to downlaod the sources anymore. Just write the command line and that's it.
There ist just one point. To get the packages installed I had to use follwoing script:
python -m pip install requests
Have a nice weekend!
good to hear this is what you are looking for .
pip install somePackage
python -m pip install somePackage
are equivalent. The second one goes through the python interpreter however. This works also if you cannot run the pip command directly (possibly because the location where it is installed is not part of your environment path variable). launching the pip command from within the Scripts folder should normally always work.
I'm glad you liked the video. The code I show in the video isn't very great and there are some things to fix, still working on a updated version. Your proyect btw, really cool!!