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)
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