Weekly market reports are a staple of the scrap metal industry. Traders, buyers, and yard managers all rely on regular market summaries to stay informed. Instead of manually compiling this report from multiple sources, you can automate the entire process using Python and the ScrapMetal API.
What the Report Includes
Our automated report will contain a current prices table showing all tracked grades with their latest prices, a week-over-week change column showing how each grade moved, a brief summary of which metals strengthened or weakened, and a chart showing the 4-week trend for key benchmark grades.
The report is generated as an HTML email that looks clean in any email client, with a fallback plain-text version.
Fetching the Data
The script makes two API calls. The first fetches current prices for all grades. The second fetches historical prices for the past 28 days to calculate weekly changes and build trend data. On the ScrapMetal API Basic plan, both calls are well within the daily limit.
Store the current prices in a dictionary keyed by ISRI code for easy lookup. Process the historical data into a structure that gives you the closing price for each grade on each day.
Calculating Changes
For each grade, compare the current price to the price from 7 days ago. Express the change both as an absolute number and as a percentage. Categorize each change as up, down, or flat using a threshold of 0.5 percent to filter out noise.
Generate a text summary by counting how many grades moved up versus down. Something like: 8 of 14 tracked grades rose this week, led by Bare Bright copper which gained 2.3 percent. Ferrous grades were mixed, with HMS 1 flat while Busheling added $8 per ton.
Building the HTML Email
Construct the email using Python string formatting with an HTML template. The price table uses standard HTML table elements with inline CSS for email client compatibility. Color the change column green for increases and red for decreases.
For the trend chart, generate a simple inline SVG sparkline for each benchmark grade. SVG renders in most modern email clients and does not require external image hosting. Keep the charts simple: a 4-week line showing direction is more useful than a complex visualization in an email.
Sending the Email
Use Python's smtplib and email.mime modules to send the report. Gmail, Outlook, and most SMTP providers work. For a more reliable setup, use a transactional email service like SendGrid or Mailgun, which offer free tiers sufficient for a weekly report.
Scheduling
Run the script every Monday morning using a cron job on a Linux server, a scheduled task on Windows, or a cloud scheduler like AWS EventBridge or Railway's cron feature. The script runs in under 30 seconds, so even the cheapest hosting option handles it easily.
Extending the Report
Once the basic report is working, consider adding month-over-month changes for longer-term context, a section highlighting grades with unusual moves, or a comparison of current prices to their 52-week high and low. Each enhancement requires only additional data processing on the same API responses.