Switching from Javascript to Python for scripting iTunes via the COM interface on Windows and am having some confusion with iTunes dates.
Trying to check songs to see which have been added since the last time the script ran and can't seem to figure out how to do that comparison. Googling around for a couple hours hasn't enabled me to make any progress. Javascript had some tricky iTunes date conversion issues so maybe it's similar weirdness, or perhaps I'm just making a noob Python mistake (sorry about that!).
When I print the DateAdded return's type with the type function I get "time" but I can't seem to use any time functions to accomplish my aim. For the song I'm working with for testing, the DateAdded variable prints out as "02/24/18 20:52:02" which is indeed the song's correct date added value. Not sure what additional information might be useful to you if it is an odd iTunes conversion issue, but am more than happy to provide any you request.
Thanks very much.
Related
For a project I am trying to communicate with an ASIC bitcoin mining machine, specifically a WhatsMiner using Python.
There is a pretty decent guide online that outlays the basic structure of how to do this, and the commands it shows work great on my miner.
However, what I am wanting to do is be able to set both the 'power percent', as well as the 'target frequency' of the machine.
The json format of how these are to be written is outlined in their API documentation which I have included screenshots of.
Throughout university, I haven't touched much json, so am having some trouble with this. To give you an idea of what I am doing, I have followed the GitHub guide above and changed the 'cmd' parameter to either "set_power_pct", or "set_target_freq". I then have changed the 'additional paramaters' to the corrosponding values outlined in the API guide.
Sorry if I am just making a dumb mistake, I really appreciate anyone's help!
Thanks
Beyond this, I have spent a bit of time search google, as well as tested this while connected to the miner. The code is not throwing up any errors, but just isn't changing how the miner is running. As I had alluded to, when I try simple commands to turn the miner on or off, this works fine.
I'm not asking for someone to write out specific codes for me, but rather just point me towards the general direction.
Sometimes after writing and pinning a comment under a Youtube video, it disappears!
It may happen hours later, it may happen a few minutes later, all randomly. Then re-appears hours later, not sure why.
Since I am currently learning programming (python), I might as well try to tackle the problem myself. I want to make a program that regularly checks if the pinned comment is still present, and if not, send me an alert in whatever way so I can go write and pin a new comment for the time being. (and maybe learn a few things during the process)
So far I learned some basic stuff like how to get source code from a webpage, output it to somewhere like a txt file, and also searching with Regex. However when I check out the source code of a Youtube video, the comments text aren't there. Where do I begin learning about the necessary things needed to make this program work?
Question
I am interested in web scraping and data analysis and I would like to develop my skills by writing a program using Python 2.7 that will monitor changes in stock prices. My goal is to be able to compare two stocks (for the time being) at certain points throughout the day, save that info into a document format easily handled by pandas (which I will learn how to use after I get this front end working). In the end I would like to map relationship trends between chosen stocks (when this one goes up by x what effect does that have on the other one). This is just a hobby project so it doesn't matter if the code is production quality.
My Experience
I am a brand new Python programmer (I have a very basic understanding of python and no real experience with any non-included modules) but I do have a technical background so if the answer to my question requires reading and understanding documentation intended for intermediate level programmers that should be OK.
For the basics I am working my way through Learning Python: Powerful Object-Oriented Programming by Mark Lutz if this helps any.
What I'm Looking For
I recognize this is a very broad subject and I am not asking for anyone to write any actual code examples or anything. I just want some direction as to where to go to get information more specific to my interests and goals.
This is actually my first post on this forum so please forgive me if this doesn't follow best practices for posting. I did search for other questions like mine and read the posting tips docs prior to writing this.
So, you want to web-scrape? If you're using Python 2.7, then you'll want to look into the urllib2, requests and BeautifulSoup libraries. If you're using Python 3.x, then you'll want to peek at urllib, urllib.request, and BeautifulSoup, again. Together, these libraries should accomplish everything you're looking to do in terms of web-scraping.
If you're interested in scraping stock data, might I suggest the yahoo_finance package? This is a Python wrapper for the Yahoo Finance API. Whenever I've done things with stock data in the past, this module was invaluable. There's also googlefinance, too. It's much easier to use these already-developed wrappers to extract stock info, rather than scraping hundreds (if not thousands) of web pages to get the data you want.
My company has slightly more than 300 vehicle based windows CE 5.0 mobile devices that all share the same software and usage model of Direct Store Delivery during the day then doing a Tcom at the home base every night. There is an unknown event(s) that results in the device freaking out and rebooting itself in the middle of the day. Frequency of this issue is ~10 times per week across the fleet of computers that all reboot daily, 6 days a week. The math is 300*6=1800 boots per week (at least) 10/1800= 0.5%. I realize that number is very low, but it is more than my boss wants to have.
My challenge, is to find a way to scan through several thousand logfille.txt files and try to find some sort of pattern. I KNOW there is a pattern here somewhere. I’ve got a couple ideas of where to start, but I wanted to throw this out to the community and see what suggestions you all might have.
A bit of background on this issue. The application starts a new log file at each boot. In an orderly (control) log file, you see the app startup, do its thing all day, and then start a shutdown process in a somewhat orderly fashion 8-10 hours later. In a problem log file, you see the device startup and then the log ends without any shutdown sequence at all in a time less than 8 hours. It then starts a new log file which shares the same date as the logfile1.old that it made in the rename process. The application that we have was home grown by windows developers that are no longer with the company. Even better, they don’t currently know who has the source at the moment.
I’m aware of the various CE tools that can be used to detect memory leaks (DevHealth, retail messages, etc..) and we are investigating that route as well, however I’m convinced that there is a pattern to be found, that I’m just not smart enough to find. There has to be a way to do this using Perl or Python that I’m just not seeing. Here are two ideas I have.
Idea 1 – Look for trends in word usage.
Create an array of every unique word used in the entire log file and output a count of each word. Once I had a count of the words that were being used, I could run some stats on them and look for the non-normal events. Perhaps the word “purple” is being used 500 times in a 1000 line log file ( there might be some math there?) on a control and only 4 times on a 500 line problem log? Perhaps there is a unique word that is only seen in the problem files. Maybe I could get a reverse “word cloud”?
Idea 2 – categorize lines into entry-type and then look for trends in the sequence of type of entry type?
The logfiles already have a predictable schema that looks like this = Level|date|time|system|source|message
I’m 99% sure there is a visible pattern here that I just can’t find. All of the logs got turned up to “super duper verbose” so there is a boatload of fluff (25 logs p/sec , 40k lines per file) that makes this even more challenging. If there isn’t a unique word, then this has almost got to be true. How do I do this?
Item 3 – Hire a windows CE platform developer
Yes, we are going down that path as well, but I KNOW there is a pattern I’m missing. They will use the tools that I don’t have) or make the tools that we need to figure out what’s up. I suspect that there might be a memory leak, radio event or other event that platform tools I’m sure will show.
Item 4 – Something I’m not even thinking of that you have used.
There have got to be tools out there that do this that aren’t as prestigious as a well-executed python script, and I’m willing to go down that path, I just don’t know what those tools are.
Oh yeah, I can’t post log files to the web, so don’t ask. The users are promising to report trends when they see them, but I’m not exactly hopeful on that front. All I need to find is either a pattern in the logs, or steps to duplicate
So there you have it. What tools or techniques can I use to even start on this?
was wondering if you'd looked at the ELK stack? It's an acronym for elasticsearch, kibana and log stash and fits your use case closely; it's often used for analysis of large numbers of log files.
Elasticsearch and kibana gives you a UI that lets you interactively explore and chart data for trends. Very powerful and quite straight forward to set up on a Linux platform and there's a Windows version too. (Took me a day or two of setup but you get a lot of functional power from it). Software is free to download and use. You could use this in a style similar to idea 1 / 2
https://www.elastic.co/webinars/introduction-elk-stack
http://logz.io/learn/complete-guide-elk-stack/
On the question of Python / idea 4 (which elk could be considered part of) I haven't done this for log files but I have used Regex to search and extract text patterns from documents using Python. That may also help you find patterns if you had some leads on the sorts of patterns you are looking for.
Just a couple of thoughts; hope they help.
There is no input data at all to this problem so this answer will be basically pure theory, a little collection of ideas you could consider.
To analize patterns out of a bunch of many logs you could definitely creating some graphs displaying relevant data which could help to narrow the problem, python is really very good for these kind of tasks.
You could also transform/insert the logs into databases, that way you'd be able to query the relevant suspicious events much faster and even compare massively all your logs.
A simpler approach could be just focusing on a simple log showing the crash, instead wasting a lot of efforts or resources trying to find some kind of generic pattern, start by reading through one simple log in order to catch suspicious "events" which could produce the crash.
My favourite approach for these type of tricky problems is different from the previous ones, instead of focusing on analizing or even parsing the logs I'd just try to reproduce the bug/s in a deterministic way locally (you don't even need to have the source code). Sometimes it's really difficult to replicate the production environment in your the dev environment but definitely is time well invested. All the effort you put into this process will help you to solve not only these bugs but improving your software much faster. Remember, the more times you're able to iterate the better.
Another approach could just be coding a little script which would allow you to replay logs which crashed, not sure if that'll be easy in your environment though. Usually this strategy works quite well with production software using web-services where there will be a lot of tuples with data-requests and data-retrieves.
In any case, without seeing the type of data from your logs I can't be more specific nor giving much more concrete details.
I wrote a python script that reads in text from a file and writes a text file of definitions. I want to somehow integrate my program with a webpage for the whole world to see.
I want to be able to retrieve input text from one text box, have the python script process it, then display the output in the other text box.
I have done quite a bit of research thus far but I am still unsure of the best way to go about doing this. I tried using google's app engine but encountered too many problems, for example the app engine runtime environment uses python 2.5.2, I wrote my program using 3.1.2. Other than that I just felt that I was beginning to waste my time trying to port my program over.
I'm starting to think that javascript is the way to go or maybe pyjamas. I was also wondering if it would be possible to just have the python program constantly running on the server and to perform a system call.
I posses very little knowledge when it comes to web development. I appreciate any advice.
You could use the cgi module and create a CGI script, if your server supports it.
It's a much bigger question, involving:
Where are you going to host the site,
How slow is the script (can it execute in a few seconds or not),
Does it need access data from files or a database,
How complex is it,
etc.
I would suggest you read about Django:
http://docs.djangoproject.com/en/1.2/
That is probably the easiest way to set up a simple web site, but is also very powerful if you want to do something more in the future (related to this project or not).
However, since your script is Python 3 only, you don't have too many options, see this question:
https://stackoverflow.com/questions/373945/what-web-development-frameworks-support-python-3
I suppose, if not too hard, it is worth thinking about converting it to Python 2.7.
If that is an option, then you might very well go down to Python 2.5 and use Google App Engine. It gives you many things for free and you really don't need to worry about many things that you would if you were to set up your server. It includes a modified (better to say, shrunk down) version of Django 1.1. When you say you are wasting your time porting from 3.x to 2.5, I guess you were not counting the time that you will waste setting all other things up.