接入教程
1. 访问hebcal官网注册获取API密钥
2. 调用convert接口进行历法日期转换
3. 使用holidays端点查询节日时间表
4. 通过shabbat参数获取安息日精确时间
5. 根据时区参数调整返回时间格式
获取犹太节日列表
python
import requests
url = 'https://www.hebcal.com/hebcal'
params = {
'v': '1',
'cfg': 'json',
'maj': 'on',
'min': 'off',
'mod': 'on',
'nx': 'on',
'year': '2024',
'month': 'x',
'ss': 'on',
'mf': 'on',
'c': 'on'
}
response = requests.get(url, params=params)
data = response.json()
print('Holidays:', data.get('items', []))
转换公历到希伯来历
php
<?php
$url = 'https://www.hebcal.com/converter';
$params = [
'cfg' => 'json',
'g' => '2024-12-25',
'gs' => 'on',
'strict' => '1'
];
$ch = curl_init($url . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);
?>
获取安息日时间
javascript
const fetch = require('node-fetch'); // 或浏览器原生fetch
async function getShabbatTimes() {
const url = 'https://www.hebcal.com/shabbat';
const params = new URLSearchParams({
cfg: 'json',
geonames: 'on',
city: 'Jerusalem',
M: 'on',
a: 'on'
});
const response = await fetch(`${url}?${params}`);
const data = await response.json();
console.log('Shabbat times:', data.items);
}
getShabbatTimes();
常见问题
这个API是免费的吗?
是的,hebcal.com提供的API目前对个人和非商业用途免费使用,但可能有调用频率限制。商业用途建议查看其官方网站的使用条款。
API是否需要认证密钥?
根据官方文档,大部分基础功能无需API密钥即可调用。但某些高级功能或高频率调用可能需要注册获取密钥。
返回的数据格式是什么?
API默认支持JSON和iCalendar格式。通过在请求参数中设置'cfg=json'可获取JSON响应,设置'cfg=ical'可获得iCalendar格式数据。
Aitishiku.com