Move Flickr sent-mail cookies into local config file

This commit is contained in:
Edward Betts 2026-02-07 14:41:41 +00:00
parent 2819652afd
commit 252a854e76
5 changed files with 127 additions and 79 deletions

131
README.md
View file

@ -1,89 +1,88 @@
# Flickr Photo Finder for Wikipedia Articles
# Flickr Mail
Tool lives here: <https://edwardbetts.com/flickr_mail/>
This tool is designed to help you find photos on Flickr for Wikipedia articles
and contact the photographer. It's a Python application that leverages the Flask
framework for web development.
Flickr Mail is a Flask app that helps find Flickr photos for Wikipedia articles
and contact photographers to request Wikipedia-compatible licensing.
## Table of Contents
- [Introduction](#introduction)
- [Usage](#usage)
- [Error Handling](#error-handling)
- [Running the Application](#running-the-application)
## What It Does
## Introduction
- Searches Flickr from a Wikipedia article title/URL
- Shows license status for each result (free vs non-free CC variants)
- Builds a ready-to-send Flickr message for non-free licenses
- Finds image-less articles in a Wikipedia category
- Shows recent Commons uploads that came from Flickr mail outreach
This tool is developed and maintained by Edward Betts (edward@4angle.com). Its
primary purpose is to simplify the process of discovering and contacting
photographers on Flickr whose photos can be used to enhance Wikipedia articles.
## Project Layout
### Key Features
- **Integrated Flickr search**: Enter a Wikipedia article title and see Flickr
photos directly in the interface - no need to visit Flickr's search page.
- **Photo grid with metadata**: Search results display as a grid of thumbnails
showing the user's name and license for each photo.
- **License handling**: Photos with Wikipedia-compatible licenses (CC BY,
CC BY-SA, CC0, Public Domain) are highlighted with a green badge and link
directly to the Commons UploadWizard. Non-free CC licenses (NC/ND) show a
tailored message explaining Wikipedia's requirements. Supports both CC 2.0
and CC 4.0 license codes.
- **One-click message composition**: Click any photo to compose a permission
request message with the photo displayed alongside, showing the user's Flickr
profile and current license.
- **Previous message detection**: The message page checks sent mail history and
warns if you have previously contacted the user.
- **Category search**: Find Wikipedia articles without images in a given
category, with links to search Flickr for each article.
- **Pagination**: Browse through thousands of search results with page navigation.
- **Recent uploads showcase**: The home page displays recent Wikimedia Commons
uploads that were obtained via Flickr mail requests, with links to the
Wikipedia article and user's Flickr profile.
- Handle exceptions gracefully and provide detailed error information.
- `main.py`: Flask app routes and core logic
- `templates/`: UI templates
- `download_sent_mail.py`: sync Flickr sent messages into DB
- `download_commons_contributions.py`: sync Commons contributions into DB
- `update_flickr_uploads.py`: derive `flickr_uploads` from contributions/sent mail
- `flickr_mail.db`: SQLite database
## Usage
## Database Pipeline
To use the tool, follow these steps:
The recent uploads section depends on a 3-step pipeline:
1. Start the tool by running the script.
2. Access the tool through a web browser.
3. Enter a Wikipedia article title or URL, or use "Find articles by category"
to discover articles that need images.
4. Browse the Flickr search results displayed in the interface.
5. Click on a photo to select it. If the license is Wikipedia-compatible, you'll
be linked to the Commons UploadWizard. Otherwise, a message is composed to
request a license change.
6. Copy the subject and message, then click "Send message on Flickr" to contact
the user.
1. `./download_sent_mail.py` updates `sent_messages`
2. `./download_commons_contributions.py` updates `contributions`
3. `./update_flickr_uploads.py` builds/updates `flickr_uploads`
## Error Handling
`main.py` only reads `flickr_uploads`; it does not populate it.
The application includes error handling to ensure a smooth user experience. If
an error occurs, it will display a detailed error message with traceback
information. The error handling is designed to provide valuable insights into
any issues that may arise during use.
## UploadWizard Detection
## Running the Application
`update_flickr_uploads.py` supports both Commons UploadWizard comment styles:
To run the application, ensure you have Python 3 installed on your system. You
will also need to install the required Python modules mentioned in the script,
including Flask, requests, and others.
- `User created page with UploadWizard` (older)
- `Uploaded a work by ... with UploadWizard` (newer)
1. Clone this repository to your local machine.
2. Navigate to the project directory.
3. Run the following command to start the application:
It first tries to extract a Flickr URL directly from the contribution comment.
If absent, it falls back to Commons `extmetadata.Credit`.
## Local Run
Install dependencies (example):
```bash
pip install flask requests beautifulsoup4 sqlalchemy
```
Start the app:
```bash
python3 main.py
```
4. Access the application by opening a web browser and visiting the provided URL
(usually `http://localhost:5000/`).
Then open:
That's it! You can now use the Flickr Photo Finder tool to streamline the
process of finding and contacting photographers for Wikipedia articles.
- `http://localhost:5000/`
If you encounter any issues or have questions, feel free to contact Edward Betts
(edward@4angle.com).
## Refresh Data
Happy photo hunting!
Run in this order:
```bash
./download_sent_mail.py
./download_commons_contributions.py
./update_flickr_uploads.py
```
Before running `./download_sent_mail.py`, create local auth config:
```bash
cp download_sent_mail.example.json download_sent_mail.local.json
```
Then edit `download_sent_mail.local.json` and set `cookies_str` to your full
Flickr `Cookie` header value.
## Notes
- `download_commons_contributions.py` uses an overlap window of known-only
batches before stopping to avoid full-history scans while still catching
shallow gaps.
- If a known Commons upload is missing from `flickr_uploads`, re-run the full
3-step pipeline above.