Twitter Streaming API Application - Where To Host? - python

I've written a python script that connects to the Twitter Streaming API. This is a consistent connection that I needs to kept alive as it feeds data into my overall application. Currently this is running on my own machine on Ubuntu; however I'm trying to find a service online that can host my file and run the script continuously. I've heard of using Daemons to do this?
Is there a service out there that can do what I'm looking for?
Cheers!

You might want to ask this over on Server Fault or Super User, as it might not be appropriate for Stack Overflow.
I used a remote desktop connection with Amazon EC2 for a python script that stored Reddit comments. Back when I had it storing 200-500 comments every 3-4 minutes 24/7 it cost me about $0.50 a month (it's $0.001 for every IO past 1,000,000 IOs or something like that).
It's free for up to a year and you get 30 GB of hard drive storage. You can only use certain types of server OSs for free, though.
I believe you can use Microsoft Azure for this as well but I don't know what their pricing is like.

Related

Google Assistant API, controlling a light switch connected to Google Home

I have machine A that just cranks out .png files. It gets synced to machine B and I view it on machine B.
Sometimes machine A crashes for whatever reason and stops doing the scheduled jobs, which means then files on machine B will be old.
I want machine B to run a script to see if the file is older than 1 day, and if it is, then reset the power switch on machine A, so that it can be cold booted. The switch is connected to Google Home but understand I have to use the Assistant API.
I have installed the google-assistant-sdk[samples] package. Can someone show me some code on how to query and return all devices then flip the switch on and off on that device?
Unfortunately, many smart home companies are building products for consumers, not developers. Google's SDK is letting developers stream consumer voice requests to their servers and turning that into actions. Gosund, similarly, is only interested in API access for Amazon and Google. They're API is probably not documented for public use.
To answer your specific question, if you want to use the Google Assistant SDK, you would name your switch something like "Server A Switch" and record a short clip of you saying "Turn off Server A Switch" and "Turn on Server A Switch" and send those two google. The way google matches the requests with your particular account is through OAuth2 tokens, which google will give you in exchange for valid sign in credentials.
If Gosund works with Google Assistant, it has a standard OAuth2 server endpoint as well as a Google Assistant compliant API endpoint. I only recommend this if you want to have some fun reverse engineering it.
In your Google Assistant app, if you try adding the Gosund integration, the first screen popup is the url endpoint where you can exchange valid Gosund account credentials for a one-time code which you can then exchange for OAuth2 access and refresh tokens. With the access token you can theoretically control your switch. The commands you'll want to send are standardized by Google. However, you'll have to figure out where to send them. The best bet here is probably to email their developers.
Are you familiar with OAuth2? If not, I don't recommend doing any of the above.
Your other option is to prevent Server A from hardware crashes. This is what I recommend as the least amount of work. You should start with a server that never crashes, keep it that way and add stuff on top of it. If you only have two servers, they should be able to maintain many months of uptime. Run your scheduled jobs using cron or systemctl and have a watchdog that restarts the job when it detects an error. If your job is crashing the server maybe put it in a VM like docker or something, which gives you neat auto-restart capabilities off the bat.
Another hacky thing you can do is schedule your gosund plug to turn off and on once a day through their consumer UI or app, or at whatever frequency you feel like is most optimal.
The google-assistant-sdk is intended for processing audio requests.
From the doc:
Your project captures an utterance (a spoken audio request, such as What's on my calendar?), sends it to the Google Assistant, and receives a spoken audio response in addition to the raw text of the utterance.
While you could use that with some recorded phrases it makes more sense to connect to the switch directly or use a service like IFTTT. What kind of switch is it?

Connect REST API on Pi to the Cloud

I am relatively new to programming. I have a project where I need to control things like pumps and read data from sensors. I currently have a flask webserver set up on a raspberry and can access that website only from within my local network.
My objective is to change my flask webserver to a flask REST APi. Then I want to set up my raspberry pi on a cloud/iot platform and control my pi over the cloud via the flask REST api.
Any idea on how to best do this? Ive been researching it a lot and could use some help.
I would setup the api endpoints like you discussed. Those endpoints I assume would allow you to control the sensors and whatever other hardware is attached to the GPIO. Then as you mentioned you would expose that API to some sort of an IOT platform. AWS offers a nice solution however there are many.
I have come a relatively long way from what I knew when asking this question. For other new programmers trying to figure out how to bring their project/idea to reality here is what I did to deploy my local flask web server on the pi to "the cloud":
I used a company named linode to host my web server on, but there are many other cloud platforms you could choose from like digital ocean and heroku. All I did was purchase their entry level plan, connect via ssh to the new server, copy over the files containing my web server, and add security provisions. Then you can use ssh to connect to your server and use the terminal to do what you need. This was the processes that I followed to deploy to the cloud. There are an abundance of options and ways to do this, but I found this option relatively flexible and cost effective...giving me the chance to participate in the IoT world.
I know this information is obvious to a lot of experienced programmers, but for the ones just getting started I hope this explanation can provide some clarity on your way forward.

How can I upload my python trading bot to the internet for auto-trading?

I have written a python code that I can run it on my computer. It gets stock data from a website by GET request. Then it does some calculations on upon these online data and decides to send a buy/sell request to my broker's account.
All of these works fine on my computer, but I like to upload my code on a web server to preventing electricity/internet disconnection. I think I should upload my code on a virtual server, but this is all the thing I know and I don't have more experience or knowledge about it. I don't know if it is what I need, how can I do that?
In my experience of making some simple web pages, we should put our main code inside the public.html file? So should I buy a web host and wrap my python code inside a .html file?
Sorry if they are simple/stupid questions but I couldn't find any answer or guidence for doung what I want, so I asked here!
With the info you provide I can't really be sure how your script is ran.
I presume you run it by shell in that case a simple vps should suffice.
No need to mess around with a webserver.
Maybe look at Digital Ocean. They are a market leader and the simple $5 option probably enough for your purpose.
When you set it up you can connect to it with ssh (preferably with a ssh key because you are working with financial data) and setup your python script as if it were your own computer.
Ps. I don't work for digital ocean or get money from the link. It is just an example, any vps will work.

Python implementing simple web data storage

I am trying to develop a python PyQt program that allow user to enter data about personal particulars and review them at a later time for processing purpose.
The program will be used by less than 5 persons at the same time. So, i am thinking to use Sqlite3 database as i believe it should be able to cope for that amount of traffic.
The frame work i have in mind is that, the clients will have their own copy of my python pyqt program on each machine. Whenever they perform any operations that required data read/write, it will connect to the server thorough internet and read/write from the sqlite.db on the server.
Basically, the server will be nothing but a remote data storage.
Currently, i am able to create the required GUI for data inputs by using various widgets like QlineEdit, QCombobox, QTextEdit and so on.
But i have never done network programming before, thus i have no idea how to implement a server that store the sqlite data file for my software. So my questions are
(1) if i have a PC that has 24/7 internet connection, how do i set it up so that it can act as a server that store the data file for my software?
(2)In what way can/should my program communicate to that server through internet.
Even if you can't give me exact answer, i would appreciate if you can provide me some information of so that i look up and study about it.
Any constructive advice will be appreciated.
FYI: all the PCs will be running windows XP SP3 32 bits.
There are different ways for a client to communicate with a server.
You can use
XMLRPC to create an object with methods that are called on the server side
You can use HTTP and REST for the server with the library requests or urllib for the client
For the latter you can use flask, bottle, django or other frameworks to create a website that serves the content
(tutorials)
You can use Pyro to remotely access the objects on the server. Useful if the clients should also communicate with eachother.
You can create your own protocol. You will learn a lot and value the other options.
The list is not complete
I suggest that you have a look at XMLRPC if that fits. For number 2 I can say that many APIs use such a HTTP-interface (twitter, github, facebok, google). It is easy to use also for other people.
Security is important. I am not an expert. If you send username and password in plain text then use SSL to encrypt the connection. If you can not get ssl to work with python you can use stunnel.

How to benchmark web chat performance?

I've just created a web chat server with Tornado over Python. The communication mechanism is to use long-polling and I/O events.
I want to benchmark this web chat server at large scale, meaning I want to test this chat server (Tornado based) to see how many chatters it can withstand.
Because I'm using cookies to identify sessions, presently I can only test with maximum 5 (IE, Firefox, Chrome, Safari, Opera) sessions per computer (cookie path has no use coz everything goes thru' the same web page), but in my office we only have limited number of computers.
I want to test this Tornado app at the extreme, hopefully it can withstand few thousand concurrent users like Tornado is advertising, but having no clue how to do this!
I would run the server in a mode where you let the client tell which client they are. i.e. change the code so it can be run this way as required. This is less secure, but makes testing easier. In production, don't use this option. This will give you a realistic test from a small number of client machines.

Categories