sunrise-sunset: Create /api/sunrise-sunset-photo endpoint
This commit is contained in:
parent
363051c35e
commit
135c54ca82
12 changed files with 5764 additions and 135 deletions
13
prettierrc
13
prettierrc
|
|
@ -1,6 +1,9 @@
|
|||
{
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 4,
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
}
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 4,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"printWidth": 120,
|
||||
"arrowParens": "always",
|
||||
"bracketSpacing": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import datetime
|
|||
import utils
|
||||
import photos
|
||||
|
||||
|
||||
|
||||
class DailyPhoto:
|
||||
def __init__(self, date: datetime.date, photo: photos.SunriseOrSunsetPhoto):
|
||||
self.date = date
|
||||
|
|
@ -26,6 +24,11 @@ class DailyPhotoSet:
|
|||
self.photos.sort(key=lambda photo: photo.photo.id)
|
||||
self._date += datetime.timedelta(days=1)
|
||||
|
||||
def as_json(self) -> str:
|
||||
return json.dumps({
|
||||
"photos": [photo.as_dict() for photo in self.photos]
|
||||
})
|
||||
|
||||
@property
|
||||
def photos(self) -> list[DailyPhoto]:
|
||||
return list(sorted(self._photos, key=lambda photo: photo.date))
|
||||
|
|
@ -34,35 +37,25 @@ class DailyPhotoSet:
|
|||
def current_date(self) -> datetime.date:
|
||||
return self._date;
|
||||
|
||||
def as_json(self) -> str:
|
||||
return json.dumps({
|
||||
"photos": [photo.as_dict() for photo in self.photos]
|
||||
})
|
||||
|
||||
|
||||
def get_all_photos() -> list[photos.SunriseOrSunsetPhoto]:
|
||||
file_names: list[str] = ["data/all_photos-0.json", "data/all_photos-1.json"]
|
||||
sunrise_or_sunset_photos = photos.SunriseOrSunsetPhotoSet.from_no_data();
|
||||
for file_name in file_names:
|
||||
with open(utils.make_relative_file_name(file_name), "r") as infile:
|
||||
photo_set = photos.SunriseOrSunsetPhotoSet.from_json(infile.read())
|
||||
sunrise_or_sunset_photos.add_photos(photo_set.unique_photos)
|
||||
|
||||
return sunrise_or_sunset_photos.photos_sorted_by_id
|
||||
file_name = utils.make_relative_file_name('data/all_photos.json')
|
||||
print(f"Reading {file_name}...")
|
||||
|
||||
with open(file_name, "r") as infile:
|
||||
photo_set = photos.SunriseOrSunsetPhotoSet.from_json(infile.read())
|
||||
print(f"Returning {len(photo_set.photos_sorted_by_id)} photos...")
|
||||
return photo_set.photos_sorted_by_id
|
||||
|
||||
def main():
|
||||
print("Creating daily photo mapping...")
|
||||
all_photos = get_all_photos()
|
||||
print("Found {} photos".format(len(all_photos)))
|
||||
|
||||
daily_photos = DailyPhotoSet()
|
||||
|
||||
for photo in all_photos:
|
||||
daily_photos.add_photo(photo)
|
||||
|
||||
|
||||
with open(utils.make_relative_file_name('data/daily-photos.json'), 'w') as outfile:
|
||||
with open(utils.make_relative_file_name('data/daily_photos.json'), 'w') as outfile:
|
||||
outfile.write(daily_photos.as_json())
|
||||
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,309 @@
|
|||
{
|
||||
"photos": [
|
||||
{
|
||||
"id": "EXCCct5Ctc8",
|
||||
"description": "Patrick Hendry",
|
||||
"username": "worldsbetweenlines",
|
||||
"username_url": "https://unsplash.com/@worldsbetweenlines",
|
||||
"small_url": "https://images.unsplash.com/photo-1511979962476-f2309aebebdf?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0NzZ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "WpwHJZoSAC8",
|
||||
"description": "No description",
|
||||
"username": "eberhardgross",
|
||||
"username_url": "https://unsplash.com/@eberhardgross",
|
||||
"small_url": "https://images.unsplash.com/photo-1513800453057-8e3e3beab4fa?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0Nzd8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "IzJYl8paQjE",
|
||||
"description": "No description",
|
||||
"username": "omiplekevin",
|
||||
"username_url": "https://unsplash.com/@omiplekevin",
|
||||
"small_url": "https://images.unsplash.com/photo-1561517720-0e753a0ad183?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0Nzl8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "Vnz7o7LeuDs",
|
||||
"description": "Golden Gate Bridge | San Francisco, California",
|
||||
"username": "tjkolesnik",
|
||||
"username_url": "https://unsplash.com/@tjkolesnik",
|
||||
"small_url": "https://images.unsplash.com/photo-1513062763492-3361f299fa71?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODB8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "YbD8b5c4yEY",
|
||||
"description": "No description",
|
||||
"username": "primalimagery",
|
||||
"username_url": "https://unsplash.com/@primalimagery",
|
||||
"small_url": "https://images.unsplash.com/photo-1517746212521-02550f213381?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODJ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "haYt1UXLSBE",
|
||||
"description": "No description",
|
||||
"username": "jaakkok",
|
||||
"username_url": "https://unsplash.com/es/@jaakkok",
|
||||
"small_url": "https://images.unsplash.com/photo-1610973319327-366ee72a6382?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODN8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "VKe3-DKR4Cc",
|
||||
"description": "No description",
|
||||
"username": "danones",
|
||||
"username_url": "https://unsplash.com/@danones",
|
||||
"small_url": "https://images.unsplash.com/photo-1510138246741-f15ac5c5dfb6?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODR8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "sS-aNF9ya04",
|
||||
"description": "Fire in the Sky",
|
||||
"username": "shaneguymon",
|
||||
"username_url": "https://unsplash.com/@shaneguymon",
|
||||
"small_url": "https://images.unsplash.com/photo-1524699745155-87e60faa9bc2?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODZ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "G-JJy-Yv_dA",
|
||||
"description": "Dandelion",
|
||||
"username": "breakfast_on_jupiter",
|
||||
"username_url": "https://unsplash.com/@breakfast_on_jupiter",
|
||||
"small_url": "https://images.unsplash.com/photo-1499946981954-e7f4b234d7fa?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODd8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "G75gUdmM9jY",
|
||||
"description": "No description",
|
||||
"username": "meiying",
|
||||
"username_url": "https://unsplash.com/@meiying",
|
||||
"small_url": "https://images.unsplash.com/photo-1575763081275-83c0c15e253e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODh8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "85bywAlFfSk",
|
||||
"description": "No description",
|
||||
"username": "ulysse_pcl",
|
||||
"username_url": "https://unsplash.com/@ulysse_pcl",
|
||||
"small_url": "https://images.unsplash.com/photo-1600602231465-89f83c332deb?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTF8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "tbJAOhQf4XA",
|
||||
"description": "No description",
|
||||
"username": "wildlittlethingsphoto",
|
||||
"username_url": "https://unsplash.com/@wildlittlethingsphoto",
|
||||
"small_url": "https://images.unsplash.com/photo-1570717399004-89aff64328ed?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTJ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "o7xVhGNyfV8",
|
||||
"description": "No description",
|
||||
"username": "kalaniparker",
|
||||
"username_url": "https://unsplash.com/@kalaniparker",
|
||||
"small_url": "https://images.unsplash.com/photo-1567648818142-e3b8b87e193d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTN8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "k5FfYOhpRgU",
|
||||
"description": "No description",
|
||||
"username": "wolfgang_hasselmann",
|
||||
"username_url": "https://unsplash.com/@wolfgang_hasselmann",
|
||||
"small_url": "https://images.unsplash.com/photo-1598626683811-f20ab5449dfc?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTR8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "01-B0-u5oj4",
|
||||
"description": "No description",
|
||||
"username": "sudesoyluturk",
|
||||
"username_url": "https://unsplash.com/@sudesoyluturk",
|
||||
"small_url": "https://images.unsplash.com/photo-1599598503133-fcc26529a417?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTV8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "EYA1RJrXa2w",
|
||||
"description": "No description",
|
||||
"username": "mebrooks01",
|
||||
"username_url": "https://unsplash.com/@mebrooks01",
|
||||
"small_url": "https://images.unsplash.com/photo-1567650076458-7addd9a2e271?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTZ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "Bm0Ja6LZWl4",
|
||||
"description": "Bandon sunset over the ocean and rocks",
|
||||
"username": "jennabee",
|
||||
"username_url": "https://unsplash.com/@jennabee",
|
||||
"small_url": "https://images.unsplash.com/photo-1441154283565-f88df169765a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTd8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "TyWBZWsZSSg",
|
||||
"description": "No description",
|
||||
"username": "adriel",
|
||||
"username_url": "https://unsplash.com/@adriel",
|
||||
"small_url": "https://images.unsplash.com/photo-1429081084450-1d46e2111f11?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTh8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "cTWxMRs21WE",
|
||||
"description": "When you woke up in the morning end see that from your terrace :P",
|
||||
"username": "zoltantasi",
|
||||
"username_url": "https://unsplash.com/@zoltantasi",
|
||||
"small_url": "https://images.unsplash.com/photo-1487691681075-3db7718cafe2?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTl8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "gqHCynBSbhk",
|
||||
"description": "Sunset at the coast",
|
||||
"username": "jjuuuliiaa",
|
||||
"username_url": "https://unsplash.com/@jjuuuliiaa",
|
||||
"small_url": "https://images.unsplash.com/photo-1601978537403-26fb4cf0c599?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw1MDB8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTQ0MDYy&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "kzU7FAtQESg",
|
||||
"description": "So Far Away, Again",
|
||||
"username": "davehoefler",
|
||||
"username_url": "https://unsplash.com/pt-br/@davehoefler",
|
||||
"small_url": "https://images.unsplash.com/photo-1585832047618-39f277bba846?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0Nzd8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "WukitUSJRgY",
|
||||
"description": "No description",
|
||||
"username": "wflwong",
|
||||
"username_url": "https://unsplash.com/@wflwong",
|
||||
"small_url": "https://images.unsplash.com/photo-1496631488200-c0b85f3044a7?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0Nzh8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "1Z6xmmq9Cow",
|
||||
"description": "The rising sun",
|
||||
"username": "framemily",
|
||||
"username_url": "https://unsplash.com/@framemily",
|
||||
"small_url": "https://images.unsplash.com/photo-1590813215080-79898d766fef?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0Nzl8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "4iXagiKXn3Y",
|
||||
"description": "This is a vantage point seen often on social media, and I wanted to find it, but no one was forthcoming with the info. I started to use Google Maps 3D to try and locate where this was. I knew the ballpark\u2014it had to be northeast of downtown. So after many attempts trying to find this cluster of palm trees, I eventually came across what had to be the location. This area, within Lincoln Heights, has lovely views but is off the beaten path. It was time for me to go make my photograph. That will never get old. I\u2019ve loved that process ever since I was a kid. Here\u2019s to many more in 2018!",
|
||||
"username": "sterlingdavisphotola",
|
||||
"username_url": "https://unsplash.com/@sterlingdavisphotola",
|
||||
"small_url": "https://images.unsplash.com/photo-1515896769750-31548aa180ed?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODB8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "9MZFKwr29ys",
|
||||
"description": "No description",
|
||||
"username": "rareair",
|
||||
"username_url": "https://unsplash.com/@rareair",
|
||||
"small_url": "https://images.unsplash.com/photo-1542812913-5ead62b789c2?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODF8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "5LgosqD7KaA",
|
||||
"description": "No description",
|
||||
"username": "soltus",
|
||||
"username_url": "https://unsplash.com/@soltus",
|
||||
"small_url": "https://images.unsplash.com/photo-1567705985899-c149770e5512?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODR8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "3dwLNke4RWg",
|
||||
"description": "Aerial view from homeland while the sun goes down. One of my very first shot from my dronie. Thanks to DJI. \u270c\ufe0f ",
|
||||
"username": "saudedum",
|
||||
"username_url": "https://unsplash.com/@saudedum",
|
||||
"small_url": "https://images.unsplash.com/photo-1571675030099-65464c19c332?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODV8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "4XyfbdOjAMU",
|
||||
"description": "It is morning...",
|
||||
"username": "exappiah",
|
||||
"username_url": "https://unsplash.com/it/@exappiah",
|
||||
"small_url": "https://images.unsplash.com/photo-1565353308308-461af1e3f492?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODZ8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "SIbpq4Lvzdk",
|
||||
"description": "No description",
|
||||
"username": "cbarbalis",
|
||||
"username_url": "https://unsplash.com/@cbarbalis",
|
||||
"small_url": "https://images.unsplash.com/photo-1523518165665-2186fc960d38?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODd8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "mkl2p7SOqgw",
|
||||
"description": "If you like my work, i would appreciate a donation via PayPal. You can find the link in my profile!\n\nHave a nice day!",
|
||||
"username": "znkrt",
|
||||
"username_url": "https://unsplash.com/@znkrt",
|
||||
"small_url": "https://images.unsplash.com/photo-1514210726275-826e1f34b1ac?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODh8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "y6_qu7hENhI",
|
||||
"description": "No description",
|
||||
"username": "yvonneassen",
|
||||
"username_url": "https://unsplash.com/@yvonneassen",
|
||||
"small_url": "https://images.unsplash.com/photo-1551752038-ecc202dd8bc9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0ODl8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "PclsTXKOgHU",
|
||||
"description": "When the sun has set, no candle can replace it",
|
||||
"username": "maazphotography",
|
||||
"username_url": "https://unsplash.com/@maazphotography",
|
||||
"small_url": "https://images.unsplash.com/photo-1499676277068-4f353b14870b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTF8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "LkjruCBLg9I",
|
||||
"description": "No description",
|
||||
"username": "patrickian4",
|
||||
"username_url": "https://unsplash.com/@patrickian4",
|
||||
"small_url": "https://images.unsplash.com/photo-1437243964124-5379b751d09a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTJ8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "4hIgq8jYqvE",
|
||||
"description": "No description",
|
||||
"username": "robinphilpotphotography",
|
||||
"username_url": "https://unsplash.com/@robinphilpotphotography",
|
||||
"small_url": "https://images.unsplash.com/photo-1515594243845-c534e30178ff?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTR8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "s03r1GyaYsU",
|
||||
"description": "No description",
|
||||
"username": "sashayudaev",
|
||||
"username_url": "https://unsplash.com/@sashayudaev",
|
||||
"small_url": "https://images.unsplash.com/photo-1572323353440-a81d778de18e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTV8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "VdfeYvJSKs0",
|
||||
"description": "Sunrise on the beach in the summer time at Ocean Isle Beach, North Carolina",
|
||||
"username": "cbpsc1",
|
||||
"username_url": "https://unsplash.com/ja/@cbpsc1",
|
||||
"small_url": "https://images.unsplash.com/photo-1555933588-36ac8a559925?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTZ8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "Jno8apIemHs",
|
||||
"description": "No description",
|
||||
"username": "coopery",
|
||||
"username_url": "https://unsplash.com/@coopery",
|
||||
"small_url": "https://images.unsplash.com/photo-1519337778422-6a8148ed5db4?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTd8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "6EFC0ad7Bao",
|
||||
"description": "Under the Bend\r\n\r\nTenney Park / Madison, Wisconsin",
|
||||
"username": "davehoefler",
|
||||
"username_url": "https://unsplash.com/pt-br/@davehoefler",
|
||||
"small_url": "https://images.unsplash.com/photo-1560134928-56b72fa51aaf?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0OTh8fHN1bnNldHxlbnwwfHx8fDE2NzQ1NDQwNjM&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "V18GNaBeZqM",
|
||||
"description": "Moran Falls Lookout",
|
||||
|
|
@ -16,14 +320,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1572116029288-c66028ff5d71?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDJ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "YIaRp5Pn4bM",
|
||||
"description": "This photo was taken at the top of the Niderbauen Kulm. That\u2019s a mountain here in Switzerland. We stayed there to camp and enjoyed this beautiful sunset.",
|
||||
"username": "dinoreichmuth",
|
||||
"username_url": "https://unsplash.com/@dinoreichmuth",
|
||||
"small_url": "https://images.unsplash.com/photo-1514899559777-eb59bbe0be90?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDN8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "s5Pugn21ixI",
|
||||
"description": "The sky was burning",
|
||||
|
|
@ -32,14 +328,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1506692386441-34a69696d3c7?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDR8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "cqKC4F3k7P8",
|
||||
"description": "This picture was taken as a timelapse for my Kauai Honeymoon travel video. This photo was taken at sunset on a beach in Waimea, HI.",
|
||||
"username": "jimmy_conover",
|
||||
"username_url": "https://unsplash.com/@jimmy_conover",
|
||||
"small_url": "https://images.unsplash.com/photo-1505845664900-f883fde76fb0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDV8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "r2nJPbEYuSQ",
|
||||
"description": "No description",
|
||||
|
|
@ -48,14 +336,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1542353436-312f0e1f67ff?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDZ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "ih5Kq0XowwY",
|
||||
"description": "Shot this sunset in San Diego while exploring.",
|
||||
"username": "jarvisphoto",
|
||||
"username_url": "https://unsplash.com/@jarvisphoto",
|
||||
"small_url": "https://images.unsplash.com/photo-1516326955207-c992510b289f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDd8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "qkfxBc2NQ18",
|
||||
"description": "No description",
|
||||
|
|
@ -72,14 +352,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1538425679099-774ec988c02a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDl8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "iEGXkSXRXN4",
|
||||
"description": "No description",
|
||||
"username": "cristina_gottardi",
|
||||
"username_url": "https://unsplash.com/fr/@cristina_gottardi",
|
||||
"small_url": "https://images.unsplash.com/photo-1484383707950-89c8d3276e53?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MTB8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "pRRSpbCFUOM",
|
||||
"description": "Start your day",
|
||||
|
|
@ -88,14 +360,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1516600517612-61f2e5eb9182?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MTF8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "eXSttBQoYbM",
|
||||
"description": "Nordfjordeid river sunset",
|
||||
"username": "steinart",
|
||||
"username_url": "https://unsplash.com/@steinart",
|
||||
"small_url": "https://images.unsplash.com/photo-1469903130378-57b1170cf901?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MTN8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "oCLbY6aEhIE",
|
||||
"description": "https://www.youtube.com/watch?v=CCKAWK55ThA",
|
||||
|
|
@ -120,14 +384,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1535748020240-f647f81842ee?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MTZ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "LL4gcqlNvPU",
|
||||
"description": "Cold Sunset",
|
||||
"username": "apviktor",
|
||||
"username_url": "https://unsplash.com/@apviktor",
|
||||
"small_url": "https://images.unsplash.com/photo-1501619951397-5ba40d0f75da?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MTd8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "qoy8cDnQSXo",
|
||||
"description": "Fly Out to Space",
|
||||
|
|
@ -168,22 +424,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1515567146196-4d95a6970179?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MjJ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "VmRxRz0gD_s",
|
||||
"description": "Sunset",
|
||||
"username": "jdiegoph",
|
||||
"username_url": "https://unsplash.com/@jdiegoph",
|
||||
"small_url": "https://images.unsplash.com/photo-1508020268086-b96cf4f4bb2e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MjN8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "RAJONCCrXh8",
|
||||
"description": "Mountain silhouettes during sunset",
|
||||
"username": "jplenio",
|
||||
"username_url": "https://unsplash.com/pt-br/@jplenio",
|
||||
"small_url": "https://images.unsplash.com/photo-1497010184051-25b08385ab1d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MjR8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "S3-P9mi2mSQ",
|
||||
"description": "Moonlight Morning",
|
||||
|
|
@ -192,14 +432,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1533034744568-1d14ff0a67d5?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MjV8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "-IMlv9Jlb24",
|
||||
"description": "Beautiful evening sunset",
|
||||
"username": "sgabriel",
|
||||
"username_url": "https://unsplash.com/@sgabriel",
|
||||
"small_url": "https://images.unsplash.com/photo-1503803548695-c2a7b4a5b875?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MjZ8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "wDb8v95nkak",
|
||||
"description": "No description",
|
||||
|
|
@ -224,14 +456,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1579317292307-2a885f1cc968?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0Mjl8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "K_pzZX8j3SE",
|
||||
"description": "Sunset on top of a mountain",
|
||||
"username": "leyy",
|
||||
"username_url": "https://unsplash.com/@leyy",
|
||||
"small_url": "https://images.unsplash.com/photo-1574726252024-83b799196f99?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MzB8fHN1bnJpc2V8ZW58MHx8fHwxNjc0NTA0Njkz&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunrise"
|
||||
},
|
||||
{
|
||||
"id": "XtIANT-_Lfo",
|
||||
"description": "No description",
|
||||
|
|
@ -240,14 +464,6 @@
|
|||
"small_url": "https://images.unsplash.com/photo-1557800642-59bb66a7c90d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDF8fHN1bnNldHxlbnwwfHx8fDE2NzQ1MDQ2OTQ&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "YjW8Qn85V6Y",
|
||||
"description": "Cuxhaven Beautiful Sunrise",
|
||||
"username": "davideragusa",
|
||||
"username_url": "https://unsplash.com/it/@davideragusa",
|
||||
"small_url": "https://images.unsplash.com/photo-1418513110185-f0ec221e47b4?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw0MDJ8fHN1bnNldHxlbnwwfHx8fDE2NzQ1MDQ2OTQ&ixlib=rb-4.0.3&q=80&w=400",
|
||||
"sunrise_or_sunset": "sunset"
|
||||
},
|
||||
{
|
||||
"id": "sXXLJ4gdKYo",
|
||||
"description": "Glow",
|
||||
|
|
|
|||
2666
scripts/sunrise_sunset_images/data/daily_photos.json
Normal file
2666
scripts/sunrise_sunset_images/data/daily_photos.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -8,8 +8,8 @@ def main():
|
|||
"""Get sunrise and sunset images from Unsplash API."""
|
||||
api = unsplash_api_gateway.UnsplashApi(environment_variables.UNSPLASH_ACCESS_KEY, environment_variables.UNSPLASH_SECRET_KEY)
|
||||
|
||||
sunrise_images = api.search_results_for_query(query="sunrise", page_size=100, page_number=5)
|
||||
sunset_images = api.search_results_for_query(query="sunset", page_size=100, page_number=5)
|
||||
sunrise_images = api.search_results_for_query(query="sunrise", page_size=25, page_number=20)
|
||||
sunset_images = api.search_results_for_query(query="sunset", page_size=25, page_number=20)
|
||||
|
||||
unfiltered_length = len(sunrise_images.unfiltered_results) + len(sunset_images.unfiltered_results)
|
||||
filtered_length = len(sunrise_images.results) + len(sunset_images.results)
|
||||
|
|
|
|||
|
|
@ -37,11 +37,6 @@ class SunriseOrSunsetPhoto:
|
|||
sunrise_or_sunset=data["sunrise_or_sunset"],
|
||||
)
|
||||
|
||||
@property
|
||||
def does_description_contain_opposite_daytime(self) -> bool:
|
||||
opposite_word = "sunrise" if self.sunrise_or_sunset == "sunset" else "sunset"
|
||||
return opposite_word in self.description.lower()
|
||||
|
||||
def as_json(self) -> object:
|
||||
return {
|
||||
"id": self.id,
|
||||
|
|
@ -52,6 +47,11 @@ class SunriseOrSunsetPhoto:
|
|||
"sunrise_or_sunset": self.sunrise_or_sunset
|
||||
}
|
||||
|
||||
@property
|
||||
def does_description_contain_opposite_daytime(self) -> bool:
|
||||
opposite_word = "sunrise" if self.sunrise_or_sunset == "sunset" else "sunset"
|
||||
return opposite_word in self.description.lower()
|
||||
|
||||
class SunriseOrSunsetPhotoSet:
|
||||
def __init__(self, photos: list[SunriseOrSunsetPhoto]):
|
||||
self.photos = photos
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
class UnsplashSearchResult:
|
||||
"""
|
||||
This class represents a single photo from Unsplash.
|
||||
"""
|
||||
def __init__(self, data: dict):
|
||||
self.id = data["id"]
|
||||
self._description = data["description"] or "No description"
|
||||
|
|
@ -7,9 +10,6 @@ class UnsplashSearchResult:
|
|||
self.small_url = data["urls"]["small"]
|
||||
self.json = data
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.description} : {self.small_url} by {self.username}"
|
||||
|
||||
@staticmethod
|
||||
def from_json(data: dict) -> "UnsplashSearchResult":
|
||||
formatted_data = {
|
||||
|
|
@ -40,6 +40,12 @@ class UnsplashSearchResult:
|
|||
|
||||
|
||||
class UnsplashSearchResultSet:
|
||||
"""
|
||||
This class collects a set of UnsplashSearchResults, i.e. a set of photos from Unsplash.
|
||||
We use this to filter our duplicate photos, or those which have a description which
|
||||
suggests they are the opposite of the day time we are looking for (e.g. a sunset photo
|
||||
with the word "sunrise" in the description).
|
||||
"""
|
||||
def __init__(self, json, sunrise_or_sunset: str):
|
||||
self.total = json["total"]
|
||||
self.total_pages = json["total_pages"]
|
||||
|
|
|
|||
15
src/routes/api/sunrise-sunset-photo.json/+server.ts
Normal file
15
src/routes/api/sunrise-sunset-photo.json/+server.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { SunriseSunsetController } from './SunriseSunsetController.js'
|
||||
|
||||
const controller = new SunriseSunsetController()
|
||||
|
||||
export const GET = async () => {
|
||||
const now = new Date()
|
||||
const body = controller.getSunriseSunsetPhotoForDate(now)
|
||||
|
||||
const response = {
|
||||
status: 200,
|
||||
body,
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(response.body))
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import { it, describe, expect, beforeAll } from 'vitest'
|
||||
import {
|
||||
type ISunriseSunsetController,
|
||||
SunriseSunsetController,
|
||||
} from './SunriseSunsetController'
|
||||
|
||||
describe('SunriseSunsetController', () => {
|
||||
let controller: ISunriseSunsetController
|
||||
|
||||
beforeAll(() => {
|
||||
controller = new SunriseSunsetController()
|
||||
})
|
||||
|
||||
it(`Should return a known photo for a known date`, () => {
|
||||
// GIVEN
|
||||
const aKnownDate = new Date('2023-01-24T14:00Z')
|
||||
|
||||
// WHEN
|
||||
const photo = controller.getSunriseSunsetPhotoForDate(aKnownDate)
|
||||
|
||||
// THEN
|
||||
expect(photo).toStrictEqual({
|
||||
date: '2023-01-24',
|
||||
photo: {
|
||||
id: '-rSka4Bw-EU',
|
||||
description: 'No description',
|
||||
username: 'mikejerskine',
|
||||
username_url: 'https://unsplash.com/@mikejerskine',
|
||||
small_url:
|
||||
'https://images.unsplash.com/photo-1475656106224-d72c2ab53e8d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=Mnw0MDEyNTV8MHwxfHNlYXJjaHw5M3x8c3VucmlzZXxlbnwwfHx8fDE2NzQ1MDI4MzQ&ixlib=rb-4.0.3&q=80&w=400',
|
||||
sunrise_or_sunset: 'sunrise',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it(`should return null when there is no photo for the day`, () => {
|
||||
// GIVEN
|
||||
const aDateWithoutPhoto = new Date('2020-01-01T00:00Z')
|
||||
|
||||
// WHEN
|
||||
const photo = controller.getSunriseSunsetPhotoForDate(aDateWithoutPhoto)
|
||||
|
||||
// THEN
|
||||
expect(photo).toBeNull()
|
||||
})
|
||||
})
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import data from './data.json'
|
||||
import { format as formatDate } from 'date-fns'
|
||||
|
||||
type Daytime = 'sunrise' | 'sunset'
|
||||
interface DailyPhoto {
|
||||
date: string // e.g. "2023-01-24"
|
||||
photo: {
|
||||
id: string
|
||||
description: string
|
||||
username: string
|
||||
username_url: string
|
||||
small_url: string
|
||||
sunrise_or_sunset: Daytime
|
||||
}
|
||||
}
|
||||
export interface ISunriseSunsetController {
|
||||
getSunriseSunsetPhotoForDate(date: Date): DailyPhoto | null
|
||||
}
|
||||
|
||||
export class SunriseSunsetController implements ISunriseSunsetController {
|
||||
private data: DailyPhoto[] = data.photos as any
|
||||
|
||||
getSunriseSunsetPhotoForDate(date) {
|
||||
const formattedDate = formatDate(date, 'yyyy-MM-dd')
|
||||
|
||||
return this.data.find((photo) => photo.date === formattedDate) ?? null
|
||||
}
|
||||
}
|
||||
2666
src/routes/api/sunrise-sunset-photo.json/data.json
Normal file
2666
src/routes/api/sunrise-sunset-photo.json/data.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,10 +0,0 @@
|
|||
import type { LoadEvent } from '@sveltejs/kit'
|
||||
|
||||
export const GET = async (_event: LoadEvent) => {
|
||||
return Promise.resolve({
|
||||
status: 200,
|
||||
body: {
|
||||
photos: [],
|
||||
},
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue