Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 46 additions & 49 deletions tabelog/tabelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def convert2prefecture_parameter(prefecture):
try:
return prefecture_map[prefecture]
except KeyError:
sys.exit('invalid prefecture name: %s' % prefecture)
sys.exit(f'invalid prefecture name: {prefecture}')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convert2prefecture_parameter refactored with the following changes:



class Tabelog:
Expand Down Expand Up @@ -54,47 +54,44 @@ def search_restaurant(self,
page_num=None,
result_datum=None,
):
_request_url = 'http://api.tabelog.com/Ver2.1/RestaurantSearch/?Key=%s' % self._access_key
_request_url = f'http://api.tabelog.com/Ver2.1/RestaurantSearch/?Key={self._access_key}'
if latitude:
_request_url = "%sLatitude=%f" % (_request_url, float(latitude))
if longitude:
_request_url = "%sLongitude=%f" % (_request_url, float(longitude))
if datum and latitude and longitude: ### valid if both latitude and longitude are specified
_request_url = "%sDatum=%s" % (self._request_url, str(datum))
_request_url = f"{self._request_url}Datum={str(datum)}"
if search_range:
_request_url = "%sSearchRange=%s" % (_request_url, str(search_range))
_request_url = f"{_request_url}SearchRange={str(search_range)}"
if prefecture:
_request_url = "%s&Prefecture=%s" % (_request_url, str(convert2prefecture_parameter(prefecture)))
_request_url = f"{_request_url}&Prefecture={str(convert2prefecture_parameter(prefecture))}"
if station:
query = [('Station', station)]
_request_url = "%s&%s" % (_request_url, urllib.urlencode(query))
_request_url = f"{_request_url}&{urllib.urlencode(query)}"
if result_set:
_request_url = "%s&ResultSet=%s" % (_request_url, str(result_set))
_request_url = f"{_request_url}&ResultSet={str(result_set)}"
if sort_order:
_request_url = "%s&SortOrder=%s" % (_request_url, str(sort_order))
_request_url = f"{_request_url}&SortOrder={str(sort_order)}"
if page_num:
_request_url = "%s&PageNum=%d" % (_request_url, str(page_num))
if result_datum:
_request_url = "%s&ResultDatum=%d" % (_request_url, str(result_datum))
_search_results = self._extract_items(_request_url)
_restaurants = [Restaurant(item) for item in _search_results]
return _restaurants
return [Restaurant(item) for item in _search_results]
Comment on lines -57 to +80
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Tabelog.search_restaurant refactored with the following changes:


def search_review(self, restaurant_cord, sort_order=None, page_num=None):
_request_url = 'http://api.tabelog.com/Ver1/ReviewSearch/?Key=%s&Rcd=%d' % (self._access_key, int(restaurant_cord))
if sort_order:
_request_url = "%s&SortOrder=%s" % (_request_url, sort_order)
_request_url = f"{_request_url}&SortOrder={sort_order}"
if page_num:
_request_url = "%s&PageNum=%d" % (_request_url, int(page_num))
_search_results = self._extract_items(_request_url)
_reviews = [Review(item) for item in _search_results]
return _reviews
return [Review(item) for item in _search_results]
Comment on lines -86 to +89
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Tabelog.search_review refactored with the following changes:


def search_restaurant_image(self, restaurant_cord):
_request_url = 'http://api.tabelog.com/Ver1/ReviewImageSearch/?Key=%s&Rcd=%d' % (self._access_key, int(restaurant_cord))
_search_results = self._extract_items(_request_url)
images = [Image(item) for item in _search_results]
return images
return [Image(item) for item in _search_results]
Comment on lines -96 to +94
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Tabelog.search_restaurant_image refactored with the following changes:



class Restaurant(object):
Expand All @@ -116,87 +113,87 @@ def __init__(self, soup_item):

@property
def rcd(self):
if self._rcd == None:
if self._rcd is None:
Comment on lines -119 to +116
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.rcd refactored with the following changes:

self._rcd = int(self._soup_item.find('rcd').renderContents())
return self._rcd

@property
def name(self):
if self._name == None:
if self._name is None:
Comment on lines -125 to +122
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.name refactored with the following changes:

self._name = self._soup_item.find('restaurantname').renderContents()
return self._name

@property
def tabelogurl(self):
if self._tabelogurl == None:
if self._tabelogurl is None:
Comment on lines -131 to +128
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.tabelogurl refactored with the following changes:

self._tabelogurl = self._soup_item.find('tabelogurl').renderContents()
return self._tabelogurl

@property
def tabelogmobileurl(self):
if self._tabelogmobileurl == None:
if self._tabelogmobileurl is None:
Comment on lines -137 to +134
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.tabelogmobileurl refactored with the following changes:

self._tabelogmobileurl = self._soup_item.find('tabelogmobileurl').renderContents()
return self._tabelogmobileurl

@property
def totalscore(self):
if self._totalscore == None:
if self._totalscore is None:
Comment on lines -143 to +140
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.totalscore refactored with the following changes:

self._totalscore = self._soup_item.find('totalscore').renderContents()
if self._totalscore:
self._totalscore = float(self._totalscore)
return self._totalscore

@property
def tastescore(self):
if self._tastescore == None:
if self._tastescore is None:
Comment on lines -151 to +148
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.tastescore refactored with the following changes:

self._tastescore = self._soup_item.find('tastescore').renderContents()
if self._tastescore:
self._tastescore = float(self._tastescore)
return self._tastescore

@property
def servicescore(self):
if self._servicescore == None:
if self._servicescore is None:
Comment on lines -159 to +156
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.servicescore refactored with the following changes:

self._servicescore = self._soup_item.find('servicescore').renderContents()
if self._servicescore:
self._servicescore = float(self._servicescore)
return self._servicescore

@property
def moodscore(self):
if self._moodscore == None:
if self._moodscore is None:
Comment on lines -167 to +164
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.moodscore refactored with the following changes:

self._moodscore = self._soup_item.find('moodscore').renderContents()
if self._moodscore:
self._moodscore = float(self._moodscore)
return self._moodscore

@property
def situation(self):
if self._situation == None:
if self._situation is None:
Comment on lines -175 to +172
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.situation refactored with the following changes:

self._situation = self._soup_item.find('situation').renderContents()
return self._situation

@property
def dinnerprice(self):
if self._dinnerprice == None:
if self._dinnerprice is None:
Comment on lines -181 to +178
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.dinnerprice refactored with the following changes:

self._dinnerprice = self._soup_item.find('dinnerprice').renderContents()
return self._dinnerprice

@property
def lunchprice(self):
if self._lunchprice == None:
if self._lunchprice is None:
Comment on lines -187 to +184
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.lunchprice refactored with the following changes:

self._lunchprice = self._soup_item.find('lunchprice').renderContents()
return self._lunchprice

@property
def category(self):
if self._category == None:
if self._category is None:
Comment on lines -193 to +190
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.category refactored with the following changes:

self._category = self._soup_item.find('category').renderContents()
return self._category

@property
def station(self):
if self._station == None:
if self._station is None:
Comment on lines -199 to +196
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Restaurant.station refactored with the following changes:

self._station = self._soup_item.find('station').renderContents()
return self._station

Expand All @@ -221,99 +218,99 @@ def __init__(self, soup_item):

@property
def nickname(self):
if self._nickname == None:
if self._nickname is None:
Comment on lines -224 to +221
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Review.nickname refactored with the following changes:

self._nickname = self._soup_item.find('nickname').renderContents()
return self._situation

@property
def visitdate(self):
if self._visitdate == None:
if self._visitdate is None:
Comment on lines -230 to +227
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Review.visitdate refactored with the following changes:

self._visitdate = self._soup_item.find('visitdate').renderContents()
return self._situation

@property
def reviewdate(self):
if self._reviewdate == None:
if self._reviewdate is None:
Comment on lines -236 to +233
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Review.reviewdate refactored with the following changes:

self._reviewdate = self._soup_item.find('reviewdate').renderContents()
return self._situation

@property
def usetype(self):
if self._usetype == None:
if self._usetype is None:
self._usetype = self._soup_item.find('usetype').renderContents()
return self._situation

@property
def situation(self):
if self._situation == None:
if self._situation is None:
self._situation = self._soup_item.find('situation').renderContents()
return self._situation

@property
def totalscore(self):
if self._totalscore == None:
if self._totalscore is None:
self._totalscore = self._soup_item.find('totalscore').renderContents()
if self._totalscore:
self._totalscore = float(self._totalscore)
return self._totalscore

@property
def tastescore(self):
if self._tastescore == None:
if self._tastescore is None:
self._tastescore = self._soup_item.find('tastescore').renderContents()
if self._tastescore:
self._tastescore = float(self._tastescore)
return self._tastescore

@property
def servicescore(self):
if self._servicescore == None:
if self._servicescore is None:
self._servicescore = self._soup_item.find('servicescore').renderContents()
if self._servicescore:
self._servicescore = float(self._servicescore)
return self._servicescore

@property
def moodscore(self):
if self._moodscore == None:
if self._moodscore is None:
self._moodscore = self._soup_item.find('moodscore').renderContents()
if self._moodscore:
self._moodscore = float(self._moodscore)
return self._moodscore

@property
def situation(self):
if self._situation == None:
if self._situation is None:
self._situation = self._soup_item.find('situation').renderContents()
return self._situation

@property
def dinnerprice(self):
if self._dinnerprice == None:
if self._dinnerprice is None:
self._dinnerprice = self._soup_item.find('pricedinner').renderContents()
return self._dinnerprice

@property
def lunchprice(self):
if self._lunchprice == None:
if self._lunchprice is None:
self._lunchprice = self._soup_item.find('pricelunch').renderContents()
return self._lunchprice

@property
def title(self):
if self._title == None:
if self._title is None:
self._title = self._soup_item.find('title').renderContents()
return self._title

@property
def pcsiteurl(self):
if self._pcsiteurl == None:
if self._pcsiteurl is None:
self._pcsiteurl = self._soup_item.find('pcsiteurl').renderContents()
return self._title

@property
def mobilesiteurl(self):
if self._mobilesiteurl == None:
if self._mobilesiteurl is None:
self._mobilesiteurl = self._soup_item.find('mobilesiteurl').renderContents()
return self._title

Expand All @@ -330,37 +327,37 @@ def __init__(self, soup_item):

@property
def urls(self):
if self._urls == None:
if self._urls is None:
self._urls = self._soup_item.find('imageurls').renderContents()
return self._urls

@property
def urlm(self):
if self._urlm == None:
if self._urlm is None:
self._urlm = self._soup_item.find('imageurlm').renderContents()
return self._urlm

@property
def urll(self):
if self._urll == None:
if self._urll is None:
self._urll = self._soup_item.find('imageurll').renderContents()
return self._urll

@property
def comment(self):
if self._comment == None:
if self._comment is None:
self._comment = self._soup_item.find('imagecomment').renderContents()
return self._comment

@property
def pcsiteurl(self):
if self._pcsiteurl == None:
if self._pcsiteurl is None:
self._pcsiteurl = self._soup_item.find('pcsiteurl').renderContents()
return self._pcsiteurl

@property
def mobilesiteurl(self):
if self._mobilesiteurl == None:
if self._mobilesiteurl is None:
self._mobilesiteurl = self._soup_item.find('mobilesiteurl').renderContents()
return self._mobilesiteurl

Expand Down