[PYTHON] Beginner: I made a launcher using dictionary

python


curl http://localhost/a/b

A python script example that supports issuing commands such as.

Launcher

launcher.py


#!/usr/bin/env python 
import sys
import subprocess

d = {}
d['url1'] = {'ip': '192.168.1.1', 'path': '/'}
d['url2'] = {'ip': '192.168.2.2', 'path': '/path2'}
d['url3'] = {'ip': '192.168.3.3', 'path': '/path/file'}
d['url4'] = {'ip': '192.168.4.4', 'path': '/a/b'}
d['url5'] = {'ip': 'localhost', 'path': '/a/b'}

def _help():
    print "[err] args need."
    print sorted(d)
    sys.exit(1)

def _cmd(key):
    cmd = "curl.sh "+d[key]['ip']+" "+d[key]['path']
    subprocess.call(cmd, shell=True)

if __name__ == '__main__' :
    if len(sys.argv) == 1 : _help()
    elif len(sys.argv) != 2 : _help("args wrong.")
    _cmd(sys.argv[1])

shell

curl.sh


#!/bin/sh
set -eu

ARG_IP=$1
ARG_PATH=$2
curl "http://${ARG_IP}${ARG_PATH}"

Recommended Posts

Beginner: I made a launcher using dictionary
I made a Line-bot using Python!
I made a python dictionary file for Neocomplete
I made a login / logout process using Python Bottle.
I made a python text
I made a discord bot
I made a school festival introduction game using Ren’py
I made a VGG16 model using TensorFlow (on the way)
I made a muscle training estimation app using Qore SDK
I made a Chatbot using LINE Messaging API and Python
I made a C ++ learning site
I made a CUI-based translation script (2)
I made a wikipedia gacha bot
Create a nested dictionary using defaultdict
I made a fortune with Python.
I made a daemon with Python
I made a game called Battle Ship using pygame and tkinter
I made a Dir en gray face classifier using TensorFlow --(1) Introduction
I made a Dir en gray face classifier using TensorFlow-④ Face extraction
I made a poker game server chat-holdem using websocket with python
I made a Chatbot using LINE Messaging API and Python (2) ~ Server ~
[Kaggle] I made a collection of questions using the Titanic tutorial
I made a dash docset for Holoviews
I made a payroll program in Python!
I touched "Orator" so I made a note
I made a character counter with Python
I tried playing a ○ ✕ game using TensorFlow
I tried drawing a line using turtle
I made a conversation partner like Siri
I made a script to display emoji
I made a Hex map with Python
I made a life game with Numpy
I made a stamp generator with GAN
I made a browser automatic stamping tool.
After studying Python3, I made a Slackbot
I tried using pipenv, so a memo
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a library for actuarial science
I made a WEB application with Django
I made a neuron simulator with Python
I made a Dir en gray face classifier using TensorFlow --⑩ Face classification test
I made a Dir en gray face classifier using TensorFlow --⑥ Learning program
I made a Dir en gray face classifier using TensorFlow --⑬ Playing (final)
I made a Dir en gray face classifier using TensorFlow --- ⑧ Learning execution
I made a Dir en gray face classifier using TensorFlow --⑫ Web release
I made a Dir en gray face classifier using TensorFlow --- ⑦ Learning model
I made a Dir en gray face classifier using TensorFlow --② Environment construction
I made an image discrimination (cifar10) model using a convolutional neural network.
I made a package like Weblio pop-up English-Japanese dictionary with Sublime Text3
I made a stamp substitute bot with line
I made a LINE BOT that returns a terrorist image using the Flickr API
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a spare2 cheaper algorithm for uWSGI
I made a useful tool for Digital Ocean
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I made a router config collection tool Config Collecor