[LINUX] I tried to get the RSS of the top song of the iTunes store automatically

Introduction

This article is used by students who are doing JS or something instead of memos. Don't expect the content.

1. A program that saves the acquired data to a file

#!/bin/bash
dname="/home/vagrant/workspace/itunes-rank-rss"
mkdir -p $dname
filename="${dname}/hourly-topsong-`date +'%Y%m%d%H%M'`.xml"
curl -s -H "User-Agent: CrawlBot;" -o $filename https://itunes.apple.com/jp/rss/topsongs/limit=10/xml

{#! / Bin / bash} is a description for executing a shell script in the bash shell in / bin / bash. The second line shows the directory where the variable dname stores. The third line uses the -p option to create a new directory if it doesn't exist, and it will work if it does. The fourth line assigns the XML file with the specified name to the variable filename. $ {dname} is for treating dname as a variable rather than a string. date +'%y%m%d%h%m' This is a command that outputs a date and a character string to create a file name. The fifth line uses the curl command.

2. What is the curl command?

A command to transfer data from the server or client side. The basic form is as follows.

```curl has various options. This time-s,-o,-I'm using three commands for h.

 |option|meaning|How to use|
 |:---:|:---:|:---:|
 |-o|Output the execution result to a file|curl -o Output destination PATH URL|
 |-s|Hide progress when outputting file|curl -s -o Output destination PATH URL|
 |-H|Add to file header|curl -H string|

# 3. Run in a virtual environment
 This time it will be done on Ubuntu, so start the virtual environment with iTerm2.

 Where it started
 1. Virtual Box
 2.Vagrant
 I use Ubuntu in a virtual environment that uses two software.
cd ~/vagrant/ubuntu
vagrant up
vagrant ssh

 Move to the directory where Ubuntu is installed. vagrant up is a command to start Ubuntu installed on a virtual PC, and vagrant ssh connects to SSH with the Vagrant virtual machine set.
 In order to run the shell script program, it is necessary to give the file permission to execute it, and this time I wrote it on the console so that it can be executed by all users.

#### **`chmod a+x niconico-ranking.sh`**
```sh

4. Automate file saving

Since the program described this time is automatically executed, it is executed using cron.

Set up cron with the above contents. Write the following at the end of cron and specify it every 40 minutes to execute the program.

40 * * * * /home/vagrant/workspace/itunes-rank.sh


Check the contents of the directory with the ls command, and if there is a file, it is successful. Thank you for your hard work! !!

What is XML

XML is translated as "extensible markup language" in Japanese. In XML, tags are used for the purpose of managing the enclosed character string as data in an easy-to-understand manner. XML is a language for describing data. You can make the data in the document easier to understand and exchange data. It is a language that conveys information to machines in an easy-to-understand and efficient manner.

What is cron?

Since it is a resident program (daemon) that is used as standard in many UNIX-based OSs, it starts the specified program periodically according to the schedule set by the user.

Recommended Posts

I tried to get the RSS of the top song of the iTunes store automatically
I tried to get the location information of Odakyu Bus
I tried to get the index of the list using the enumerate function
I tried to touch the API of ebay
I tried to correct the keystone of the image
I tried to get the authentication code of Qiita API with Python.
I tried to automatically extract the movements of PES players with software
Get the song name from the title of the video you tried to sing
I tried to get the movie information of TMDb API with Python
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to summarize the basic form of GPLVM
[Python] I tried to graph the top 10 eyeshadow rankings
I tried to visualize the spacha information of VTuber
[Python] I tried to get Json of squid ring 2
I tried to classify the voices of voice actors
I tried to summarize the string operations of Python
I tried to find the entropy of the image with python
I tried to find the average of the sequence with TensorFlow
I want to get the operation information of yahoo route
[Python] I tried to visualize the follow relationship of Twitter
[Machine learning] I tried to summarize the theory of Adaboost
I tried to fight the Local Minimum of Goldstein-Price Function
Keras I want to get the output of any layer !!
I tried to get various information from the codeforces API
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I tried to create a Python script to get the value of a cell in Microsoft Excel
I tried to predict the genre of music from the song title on the Recurrent Neural Network
I tried to move the ball
I tried to estimate the interval.
I want to get the name of the function / method being executed
[Linux] I tried to summarize the command of resource confirmation system
I tried to get a database of horse racing using Pandas
I tried to automate the watering of the planter with Raspberry Pi
A memorandum when I tried to get it automatically with selenium
I tried to get a list of AMI Names using Boto3
I tried to get started with Bitcoin Systre on the weekend
I tried to expand the size of the logical volume with LVM
I tried to summarize the frequently used implementation method of pytest-mock
I tried to improve the efficiency of daily work with Python
I tried to automatically collect images of Kanna Hashimoto with Python! !!
I tried to visualize the common condition of VTuber channel viewers
PhytoMine-I tried to get the genetic information of plants with Python
I tried the asynchronous server of Django 3.0
I tried to summarize the umask command
I tried to recognize the wake word
I tried to summarize the graphical modeling.
I tried to estimate the pi stochastically
I tried to touch the COTOHA API
I tried to transform the face image using sparse_image_warp of TensorFlow Addons
I tried to visualize the age group and rate distribution of Atcoder
I tried transcribing the news of the example business integration to Amazon Transcribe
When I tried to run Python, it was skipped to the Microsoft Store
zoom I tried to quantify the degree of excitement of the story at the meeting
I tried to estimate the similarity of the question intent using gensim's Doc2Vec
I tried how to improve the accuracy of my own Neural Network
I tried to solve the 2020 version of 100 language processing [Chapter 3: Regular expressions 25-29]
I measured 6 methods to get the index of the maximum value (minimum value) of the list
(Python) I tried to analyze 1 million hands ~ I tried to estimate the number of AA ~