How to send a request to the DMM (FANZA) API with python

Lottery

Trigger

DMM API that is often used by affiliates. I wrote a code to send a request with python and want to get the search result, so make a note of it. (It was quite a while ago that I actually wrote and used it)

Source code

This is a sample to get douujin work information.

# dayUtil
import datetime
# htmlUtils
import requests
from urllib.request import urlopen
# JsonParser
import json

#Domain used in request telegram
DOMAIN = "https://api.dmm.com/affiliate/v3/ItemList"
#API used in request telegram_ID
API_ID = "xxxxx"
#AFFILIATE used in request telegram_ID
AFFILIATE_ID = "xxxxx"
#SORT used in request telegram_VALUE
SORT_VALUE = "date"
#OUTPUT used in the request message
OUTPUT = "json"
#SITE used in request telegram
SITE = "DMM.R18"

# ==================================================
#html generation
# ==================================================
def create():
    jsonObject = requestToApi(10, 30, "keyword", "digital_doujin", "doujin")

# ==================================================
#Send request to API
# ==================================================
def requestToApi(hitsNum, dateFromNum, keyword, floor, service):
    response = requests.get(createRequest(hitsNum, dateFromNum, keyword, floor, service))
    jsonObject = response.json()

    return jsonObject

# ==================================================
#Request generation
# ==================================================
def createRequest(hitsNum, dateFromNum, keyword, floor, service):
    txt = DOMAIN + "?" \
    + createQueryParam("api_id", API_ID) + "&" \
    + createQueryParam("affiliate_id", AFFILIATE_ID) + "&" \
    + "hits=" + str(hitsNum) + "&" \
    + createQueryParam("sort", SORT_VALUE) + "&" \
    + createQueryParam("keyword", keyword) + "&" \
    + createDateTxt(dateFromNum) + "&" \
    + createQueryParam("output", OUTPUT) + "&" \
    + createQueryParam("site", SITE) + "&" \
    + createQueryParam("floor", floor) + "&" \
    + createQueryParam("service", service)

    return txt

# ==================================================
#Generate query parameters
# ==================================================
def createQueryParam(key, value):
    return key + "=" + value

Recommended Posts

How to send a request to the DMM (FANZA) API with python
[Introduction to Python] How to split a character string with the split function
How to read a CSV file with Python 2/3
Send a message to LINE with Python (LINE Notify)
How to send a message to LINE with curl
[Python] Explains how to use the range function with a concrete example
[Introduction to Python] How to write a character string with the format function
How to convert / restore a string with [] in python
[Python] How to draw a line graph with Matplotlib
[Introduction to Python] How to iterate with the range function?
How to create a submenu with the [Blender] plugin
[Python] How to specify the download location with youtube-dl
[Python] How to rewrite the table style with python-pptx [python-pptx]
Call the API with python3.
How to post a ticket from the Shogun API
[Python] How to create a 2D histogram with Matplotlib
How to operate Discord API with Python (bot registration)
[Python] How to draw a scatter plot with Matplotlib
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
How to identify the element with the smallest number of characters in a Python list?
I tried to simulate how the infection spreads with Python
A note about hitting the Facebook API with the Python SDK
How to convert an array to a dictionary with Python [Application]
The first API to make with python Djnago REST framework
How to use the __call__ method in a Python class
Probably the easiest way to create a pdf with Python3
How to get the last (last) value in a list in Python
How to build a python2.7 series development environment with Vagrant
How to get into the python development environment with Vagrant
[Python] The first step to making a game with Pyxel
[Introduction to Python] How to get data with the listdir function
How to write a Python class
Python: How to use async with
How to get the Python version
How to get started with Python
Hit the Etherpad-lite API with Python
[Python] How to import the library
How to use OpenPose's Python API
How to use FTP with Python
[Python] How to use Typetalk API
[Python] Create API to send Gmail
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
How to determine the existence of a selenium element in Python
Rubyist tried to make a simple API with Python + bottle + MySQL
[September 2020 version] Explains the procedure to use Gmail API with Python
[Python 3.8 ~] How to define a recursive function smartly with a lambda expression
I created a Python library to call the LINE WORKS API
How to get followers and followers from python using the Mastodon API
How to check the memory size of a variable in Python
How to make a command to read the configuration file with pyramid
How to make a surveillance camera (Security Camera) with Opencv and Python
Make a request from Device Farm (appium python) to API Gateway
[Python] Explains how to use the format function with an example
[Python] How to get a value with a key other than value with Enum
[ROS2] How to play a bag file with python format launch
Create a REST API to operate dynamodb with the Django REST Framework
How to create a serverless machine learning API with AWS Lambda
HTML email with image to send with python
A class that hits the DMM API
How to add a package with PyCharm