Mango
CT

Scraping Gas Prices in Rust

I was speaking with a friend about having some kind of app to monitor gas prices throughout the year, but moreso throughout shorter time periods, study their patterns in hopes of analyzing gas prices across locations. And I took matters into my own hands to get my friends their optimum gas stations after reading a reddit thread of how someone programmed their home assistant to monitor gas prices. Here's what I came up with:

Tech Stack

  • • Rust
  • • Reqwest HTTP Client
  • • GraphQL API
  • • Serde for JSON Parsing
  • • Tokio for Asynchronous Runtime

⚠️ Challenges

Handling complex API responses, identifying reliable fuel price data, and managing large JSON structures. I did this by first scraping for gas prices in small cities, majorily in IL. I ended up building it to be compatible with any city in the USA, or any valid zipcode.

API Integration

I set up a GraphQL API using Apollo Server to integrate with the GasBuddy API for fetching gas station data based on user searches. I then created functions to parse the payload for better user understanding and other functions for comparing gas station stats.

Data Analysis

I wanted to integrate the home assistant from the reddit thread, for it to give me green light when gas is cheap and red light when it is not. I also wanted to add a feature where the code is sort of smart, detecting patterns when it can, to foreshadow prices.

Development Process

Built using Rust for performance and safety. The scraper utilizes the GasBuddy GraphQL API to fetch and process gas price data efficiently.

Core Features

  • Location-based gas station data retrieval.
  • Price analysis for cheapest and most expensive stations.
  • Fuel type categorization (cash and credit).
  • Trends visualization and insights.

Technical Decisions

Leveraged Reqwest for HTTP requests and Serde for JSON handling. Chose Rust for its strong type safety and efficient performance in networked applications. Ended up using almost 2GB of storage for the project alone, so I am trying to make this into a native app at some point.

Schema for parsing the GraphQL and GasBuddy data

The schema defined a GasStation type with fields like name, address, and price. Resolvers used Axios to fetch data from GasBuddy, processing search parameters like location or fuel type. This streamlined the retrieval of precise, filtered gas station information through structured GraphQL queries.

← Go back

Hassan MangoHassan MangoHassan MangoHassan MangoHassan MangoHassan MangoHassan MangoHassan MangoHassan MangoHassan MangoHassan MangoHassan Mango