{"id":17043424,"url":"https://github.com/leavez/fucking-beijing-bus-api","last_synced_at":"2025-04-12T15:11:01.306Z","repository":{"id":82216593,"uuid":"153924385","full_name":"leavez/fucking-beijing-bus-api","owner":"leavez","description":"北京实时公交 API","archived":false,"fork":false,"pushed_at":"2020-08-16T17:59:32.000Z","size":35,"stargazers_count":47,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T09:45:04.713Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leavez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-20T16:17:34.000Z","updated_at":"2025-02-13T10:06:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e0b8903-a751-470b-9950-082ca9235b3d","html_url":"https://github.com/leavez/fucking-beijing-bus-api","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Ffucking-beijing-bus-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Ffucking-beijing-bus-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Ffucking-beijing-bus-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leavez%2Ffucking-beijing-bus-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leavez","download_url":"https://codeload.github.com/leavez/fucking-beijing-bus-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586231,"owners_count":21128997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T09:29:30.952Z","updated_at":"2025-04-12T15:11:01.299Z","avatar_url":"https://github.com/leavez.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fucking-beijing-bus-api\n\n[![Swift](https://img.shields.io/badge/swift-5-orange.svg?style=flat)](#) \n[![Swift Package Manager](https://rawgit.com/jlyonsmith/artwork/master/SwiftPackageManager/swiftpackagemanager-compatible.svg)](https://swift.org/package-manager/)\n[![Build Status](https://travis-ci.org/leavez/fucking-beijing-bus-api.svg?branch=master)](https://travis-ci.org/leavez/fucking-beijing-bus-api)\n[![codecov](https://codecov.io/gh/leavez/fucking-beijing-bus-api/branch/master/graph/badge.svg)](https://codecov.io/gh/leavez/fucking-beijing-bus-api)\n\n北京实时公交 API。可以获得车站公交的到站情况，以及公交车的实时定位。\n\n数据来源：[北京实时公交 App](http://jtw.beijing.gov.cn/ztlm/bjssgj/) 的接口，信息相对地图 app 更准确。\n\n## Installation\n\nrequire swift 5+\n\nSwift Package Manager \n```\n.package(url: \"https://github.com/leavez/fucking-beijing-bus-api.git\", from: \"1.1.0\")\n```\n\nCocoapods\n```\n\npod \"fucking-beijing-bus-api\", :git =\u003e \"https://github.com/leavez/fucking-beijing-bus-api.git\", :tag =\u003e \"1.0.5\"\n```\n\n## Features\n\nNOTE: 所有的 block 从主线程返回，如果写 commandline 程序，注意避免死锁。\n\n```Swift\n\npublic struct BeijingBusAPI {\n\n    /// static data\n    public struct Static {\n\n        /// 获取所有线路\n        ///\n        /// 该接口把所有公交路线都返回回来，大概 2000 多条（同一条线路的两个方向视为两条），接口数据大概 40+k\n        /// 主要用来获取 lineID。一般不会变，建议缓存\n        public static func getAllLines(completion: @escaping ((Result\u003c[LineMeta]\u003e) -\u003e Void))\n\n        /// 获取线路的详细信息（如所包含的车站）\n        ///\n        /// - Parameters:\n        ///   - lineID: 所要查询的线路 ID，getAllLines 中返回的 ID。不是公交车上面写的线路号码。\n        public static func getLineDetail(ofLine lineID: String, completion: @escaping (Result\u003cLineDetail?\u003e) -\u003e Void)\n\n        public struct Cache {\n\n            /// 如果有缓存数据，先读缓存，否则再去请求网络。\n            /// 如果想清空请求数据，可以使用 cache 函数设 Key.allLines 为 nil\n            public static func getAllLinesSmartly(completion: @escaping ((Result\u003c[LineMeta]\u003e) -\u003e Void))\n\n            /// 如果有缓存数据，先读缓存，否则再去请求网络。\n            /// 如果想清空请求数据，可以使用 cache 函数设 Key.lineDetails 为 nil\n            public static func getLineDetailSmartly(ofLine lineID: String, completion: @escaping (Result\u003cLineDetail?\u003e) -\u003e Void)\n        }\n    }\n\n    /// real time data\n    public struct RealTime {\n\n        /// 批量获取公交线路对于指定车站最近一辆车的状态\n        ///\n        /// 其中虽然（stationName, indexInBusLine）都可以表示一个具体车站，但两者都要求传入。\n        ///\n        /// - Parameters:\n        ///   - stationWithLines: 需要获取的线路和对应的车站\n        ///      - lineID: 所要查询的线路 ID，getAllLines 中返回的 ID。不是公交车上面写的线路号码。\n        ///      - stationName: 车站的中文名\n        ///      - indexInBusLine: indexInBusLine\n        public static func getLineStatusForStation(_ stationWithLines: [(lineID: String, stationName: String, indexInBusLine: Int)], completion: @escaping (Result\u003c[BusStatusForStation]\u003e) -\u003e Void)\n\n        /// 获取公交线路的所有车的状态（实时位置等）\n        ///\n        /// 返回结果为数组，数组中所有信息都是相对输入参数中的车站。\n        ///\n        /// - Parameters:\n        ///   - lineID: 所要查询的线路 ID。同个线路两个方向的车，ID 是不一样的\n        ///   - indexInBusLine: 参考车站在线路中的序数\n        public static func getAllBusesStatus(ofLine lineID: String, referenceStation indexInBusLine: Int, completion: @escaping (Result\u003c[BusStatusForStation]\u003e) -\u003e Void)\n    }\n}\n\n\n```\n\n## Acknowledgment\n\n通过抓包/逆向和参考以下资料实现：\n\n- https://github.com/wong2/beijing_bus\n- https://blog.ddiu.site/bjbus-api-3/\n- https://github.com/wong2/beijing_bus/wiki/Decompile\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleavez%2Ffucking-beijing-bus-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleavez%2Ffucking-beijing-bus-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleavez%2Ffucking-beijing-bus-api/lists"}