#!/usr/bin/env python # encoding=utf-8 # Mon 27-Jul-2009 20:00 bushbo # Simple lookup server to translate kanji to RTK keywords import sys, os, types, base64, urllib, urlparse, SimpleHTTPServer, BaseHTTPServer from StringIO import StringIO # format: [frame number, keyword, kanji] (5th ed) # http://ziggr.com/heisig/ HEISIG = """ 1, one, 一 2, two, 二 3, three, 三 4, four, 四 5, five, 五 6, six, 六 7, seven, 七 8, eight, 八 9, nine, 九 10, ten, 十 11, mouth, 口 12, day, 日 13, month, 月 14, rice field, 田 15, eye, 目 16, old, 古 17, I, 吾 18, risk, 冒 19, companion, 朋 20, bright, 明 21, chant, 唱 22, sparkle, 晶 23, goods, 品 24, spine, 呂 25, prosperous, 昌 26, early, 早 27, rising sun, 旭 28, generation, 世 29, stomach, 胃 30, nightbreak, 旦 31, gall bladder, 胆 32, span, 亘 33, concave, 凹 34, convex, 凸 35, olden times, 旧 36, oneself, 自 37, white, 白 38, hundred, 百 39, in, 中 40, thousand, 千 41, tongue, 舌 42, measuring box, 升 43, rise up, 昇 44, round, 丸 45, measurement, 寸 46, specialty, 専 47, Dr., 博 48, fortune-telling, 占 49, above, 上 50, below, 下 51, eminent, 卓 52, morning, 朝 53, only, 只 54, shellfish, 貝 55, upright, 貞 56, employee, 員 57, see, 見 58, newborn babe, 児 59, beginning, 元 60, page, 頁 61, stubborn, 頑 62, mediocre, 凡 63, defeat, 負 64, ten thousand, 万 65, phrase, 句 66, texture, 肌 67, decameron, 旬 68, ladle, 勺 69, bull's eye, 的 70, neck, 首 71, fish guts, 乙 72, riot, 乱 73, straightaway, 直 74, tool, 具 75, true, 真 76, craft, 工 77, left, 左 78, right, 右 79, possess, 有 80, bribe, 賄 81, tribute, 貢 82, paragraph, 項 83, sword, 刀 84, blade, 刃 85, cut, 切 86, seduce, 召 87, shining, 昭 88, rule, 則 89, vice-, 副 90, separate, 別 91, street, 丁 92, village, 町 93, can, 可 94, place on the head, 頂 95, child, 子 96, cavity, 孔 97, complete, 了 98, woman, 女 99, fond, 好 100, likeness, 如 101, mama, 母 102, pierce, 貫 103, elder brother, 兄 104, overcome, 克 105, little, 小 106, few, 少 107, large, 大 108, many, 多 109, evening, 夕 110, eventide, 汐 111, outside, 外 112, name, 名 113, stone, 石 114, resemblance, 肖 115, nitrate, 硝 116, smash, 砕 117, sand, 砂 118, plane, 削 119, ray, 光 120, plump, 太 121, utensil, 器 122, stinking, 臭 123, exquisite, 妙 124, focus, 省 125, thick, 厚 126, strange, 奇 127, stream, 川 128, state, 州 129, obey, 順 130, water, 水 131, icicle, 氷 132, eternity, 永 133, spring, 泉 134, meadow, 原 135, petition, 願 136, swim, 泳 137, marsh, 沼 138, open sea, 沖 139, creek, 江 140, soup, 汁 141, tide, 潮 142, source, 源 143, lively, 活 144, extinguish, 消 145, but of course, 況 146, river, 河 147, overnight, 泊 148, lake, 湖 149, fathom, 測 150, soil, 土 151, spit, 吐 152, pressure, 圧 153, cape, 埼 154, hedge, 垣 155, squared jewel, 圭 156, seal, 封 157, horizon, 涯 158, Buddhist temple, 寺 159, time, 時 160, level, 均 161, fire, 火 162, inflammation, 炎 163, anxiety, 煩 164, thin, 淡 165, lamp, 灯 166, farm, 畑 167, disaster, 災 168, ashes, 灰 169, spot, 点 170, illuminate, 照 171, fish, 魚 172, fishing, 漁 173, ri, 里 174, black, 黒 175, black ink, 墨 176, carp, 鯉 177, quantity, 量 178, rin, 厘 179, bury, 埋 180, same, 同 181, den, 洞 182, trunk, 胴 183, yonder, 向 184, esteem, 尚 185, character, 字 186, guard, 守 187, perfect, 完 188, proclaim, 宣 189, wee hours, 宵 190, relax, 安 191, banquet, 宴 192, draw near, 寄 193, wealth, 富 194, savings, 貯 195, tree, 木 196, grove, 林 197, forest, 森 198, Japanese Judas-tree, 桂 199, oak, 柏 200, frame, 枠 201, treetops, 梢 202, shelf, 棚 203, apricot, 杏 204, paulownia, 桐 205, plant, 植 206, wither, 枯 207, crude, 朴 208, town, 村 209, inter-, 相 210, desk, 机 211, book, 本 212, tag, 札 213, calendar, 暦 214, plan, 案 215, parch, 燥 216, not yet, 未 217, extremity, 末 218, splash, 沫 219, flavor, 味 220, younger sister, 妹 221, vermilion, 朱 222, stocks, 株 223, young, 若 224, grass, 草 225, suffering, 苦 226, tolerant, 寛 227, dilute, 薄 228, leaf, 葉 229, imitation, 模 230, vague, 漠 231, grave, 墓 232, livelihood, 暮 233, membrane, 膜 234, seedling, 苗 235, portent, 兆 236, peach tree, 桃 237, stare, 眺 238, dog, 犬 239, status quo, 状 240, silence, 黙 241, sort of thing, 然 242, reed, 荻 243, hunt, 狩 244, cat, 猫 245, cow, 牛 246, special, 特 247, revelation, 告 248, before, 先 249, wash, 洗 250, jammed in, 介 251, world, 界 252, tea, 茶 253, fit, 合 254, pagoda, 塔 255, king, 王 256, jewel, 玉 257, treasure, 宝 258, pearl, 珠 259, present, 現 260, lunatic, 狂 261, emperor, 皇 262, display, 呈 263, whole, 全 264, plug, 栓 265, logic, 理 266, lord, 主 267, pour, 注 268, pillar, 柱 269, gold, 金 270, pig iron, 銑 271, bowl, 鉢 272, copper, 銅 273, angling, 釣 274, needle, 針 275, inscription, 銘 276, tranquillize, 鎮 277, road-way, 道 278, guidance, 導 279, crossing, 辻 280, swift, 迅 281, create, 造 282, urge, 迫 283, escape, 逃 284, environs, 辺 285, patrol, 巡 286, car, 車 287, take along, 連 288, rut, 軌 289, transport, 輸 290, in front, 前 291, each, 各 292, status, 格 293, abbreviation, 略 294, guest, 客 295, forehead, 額 296, summer, 夏 297, dispose, 処 298, twig, 条 299, fall, 落 300, superfluous, 冗 301, army, 軍 302, radiance, 輝 303, carry, 運 304, crown, 冠 305, dream, 夢 306, pit, 坑 307, tall, 高 308, receive, 享 309, cram school, 塾 310, mellow, 熟 311, pavilion, 亭 312, capital, 京 313, refreshing, 涼 314, scenery, 景 315, whale, 鯨 316, cottage, 舎 317, circumference, 周 318, week, 週 319, gentleman, 士 320, good luck, 吉 321, robust, 壮 322, villa, 荘 323, sell, 売 324, study, 学 325, memorize, 覚 326, flourish, 栄 327, write, 書 328, haven, 津 329, breed, 牧 330, aggression, 攻 331, failure, 敗 332, sheet of, 枚 333, happenstance, 故 334, awe, 敬 335, say, 言 336, admonish, 警 337, plot, 計 338, prison, 獄 339, revise, 訂 340, chastise, 討 341, instruction, 訓 342, imperial edict, 詔 343, packed, 詰 344, tale, 話 345, recitation, 詠 346, poem, 詩 347, word, 語 348, read, 読 349, tune, 調 350, discuss, 談 351, consent, 諾 352, rebuke, 諭 353, style, 式 354, test, 試 355, II (two), 弐 356, range, 域 357, burglar, 賊 358, plantation, 栽 359, load, 載 360, overgrown, 茂 361, turn into, 成 362, castle, 城 363, sincerity, 誠 364, intimidate, 威 365, destroy, 滅 366, dwindle, 減 367, scaffold, 桟 368, coin, 銭 369, shallow, 浅 370, stop, 止 371, walk, 歩 372, ford, 渉 373, repeatedly, 頻 374, agreement, 肯 375, undertake, 企 376, curriculum, 歴 377, warrior, 武 378, levy, 賦 379, correct, 正 380, evidence, 証 381, politics, 政 382, determine, 定 383, lock, 錠 384, run, 走 385, transcend, 超 386, proceed, 赴 387, surpass, 越 388, just so, 是 389, topic, 題 390, dike, 堤 391, build, 建 392, prolong, 延 393, nativity, 誕 394, cornerstone, 礎 395, bridegroom, 婿 396, garment, 衣 397, tailor, 裁 398, attire, 装 399, back, 裏 400, demolition, 壊 401, pathetic, 哀 402, distant, 遠 403, monkey, 猿 404, first time, 初 405, linen, 布 406, sail, 帆 407, hanging scroll, 幅 408, cap, 帽 409, curtain, 幕 410, canopy, 幌 411, brocade, 錦 412, market, 市 413, elder sister, 姉 414, lungs, 肺 415, sash, 帯 416, stagnate, 滞 417, thorn, 刺 418, system, 制 419, made in..., 製 420, revolve, 転 421, technique, 芸 422, rain, 雨 423, cloud, 雲 424, cloudy weather, 曇 425, thunder, 雷 426, frost, 霜 427, winter, 冬 428, heavens, 天 429, bridge, 橋 430, attractive, 嬌 431, stand up, 立 432, cry, 泣 433, badge, 章 434, vie, 競 435, sovereign, 帝 436, juvenile, 童 437, pupil, 瞳 438, bell, 鐘 439, make a deal, 商 440, legitimate wife, 嫡 441, suitable, 適 442, drip, 滴 443, enemy, 敵 444, spoon, 匕 445, north, 北 446, stature, 背 447, compare, 比 448, descendants, 昆 449, all, 皆 450, mix, 混 451, thirst, 渇 452, audience, 謁 453, brown, 褐 454, hoarse, 喝 455, delicious, 旨 456, fat, 脂 457, I (one), 壱 458, every, 毎 459, cleverness, 敏 460, plum, 梅 461, sea, 海 462, beg, 乞 463, drought, 乾 464, abdomen, 腹 465, duplicate, 複 466, lack, 欠 467, blow, 吹 468, cook, 炊 469, song, 歌 470, soft, 軟 471, next, 次 472, briar, 茨 473, assets, 資 474, figure, 姿 475, consult with, 諮 476, compensation, 賠 477, cultivate, 培 478, divide, 剖 479, sound, 音 480, darkness, 暗 481, rhyme, 韻 482, discriminating, 識 483, mirror, 鏡 484, boundary, 境 485, deceased, 亡 486, blind, 盲 487, delusion, 妄 488, laid waste, 荒 489, ambition, 望 490, direction, 方 491, disturb, 妨 492, boy, 坊 493, perfumed, 芳 494, obese, 肪 495, call on, 訪 496, set free, 放 497, violent, 激 498, undress, 脱 499, explanation, 説 500, pointed, 鋭 501, formerly, 曽 502, increase, 増 503, presents, 贈 504, east, 東 505, ridgepole, 棟 506, frozen, 凍 507, pregnancy, 妊 508, courts, 廷 509, dye, 染 510, burn, 燃 511, V.I.P., 賓 512, year-end, 歳 513, prefecture, 県 514, horse chestnut, 栃 515, ground, 地 516, pond, 池 517, insect, 虫 518, lightning bug, 蛍 519, snake, 蛇 520, rainbow, 虹 521, butterfly, 蝶 522, single, 独 523, silkworm, 蚕 524, wind, 風 525, self, 己 526, rouse, 起 527, queen, 妃 528, reformation, 改 529, scribe, 記 530, wrap, 包 531, placenta, 胞 532, cannon, 砲 533, bubble, 泡 534, tortoise, 亀 535, electricity, 電 536, dragon, 竜 537, waterfall, 滝 538, pork, 豚 539, pursue, 逐 540, consummate, 遂 541, house, 家 542, marry into, 嫁 543, overpowering, 豪 544, intestines, 腸 545, location, 場 546, hot water, 湯 547, sheep, 羊 548, beauty, 美 549, ocean, 洋 550, detailed, 詳 551, fresh, 鮮 552, accomplished, 達 553, envious, 羨 554, distinction, 差 555, don, 着 556, solely, 唯 557, char, 焦 558, reef, 礁 559, gather, 集 560, quasi-, 准 561, advance, 進 562, miscellaneous, 雑 563, female, 雌 564, semi-, 準 565, stirred up, 奮 566, rob, 奪 567, assurance, 確 568, noon, 午 569, permit, 許 570, delight, 歓 571, authority, 権 572, outlook, 観 573, feathers, 羽 574, learn, 習 575, the following, 翌 576, weekday, 曜 577, laundry, 濯 578, sayeth, 曰 579, quandary, 困 580, harden, 固 581, country, 国 582, group, 団 583, cause, 因 584, matrimony, 姻 585, park, 園 586, -times, 回 587, podium, 壇 588, store, 店 589, warehouse, 庫 590, courtyard, 庭 591, government office, 庁 592, bed, 床 593, hemp, 麻 594, grind, 磨 595, heart, 心 596, forget, 忘 597, endure, 忍 598, acknowledge, 認 599, mourning, 忌 600, intention, 志 601, document, 誌 602, loyalty, 忠 603, shish kebab, 串 604, afflicted, 患 605, think, 思 606, grace, 恩 607, apply, 応 608, idea, 意 609, concept, 想 610, breath, 息 611, recess, 憩 612, favor, 恵 613, fear, 恐 614, beguile, 惑 615, emotion, 感 616, melancholy, 憂 617, widow, 寡 618, busy, 忙 619, ecstasy, 悦 620, constancy, 恒 621, lament, 悼 622, enlightenment, 悟 623, dreadful, 怖 624, disconcerted, 慌 625, repent, 悔 626, hate, 憎 627, accustomed, 慣 628, pleasure, 愉 629, lazy, 惰 630, humility, 慎 631, remorse, 憾 632, recollection, 憶 633, pining, 慕 634, annexed, 添 635, invariably, 必 636, ooze, 泌 637, hand, 手 638, watch over, 看 639, chafe, 摩 640, ego, 我 641, righteousness, 義 642, deliberation, 議 643, sacrifice, 犠 644, rub, 抹 645, embrace, 抱 646, board, 搭 647, extract, 抄 648, confront, 抗 649, criticism, 批 650, beckon, 招 651, clear the land, 拓 652, clap, 拍 653, strike, 打 654, arrest, 拘 655, discard, 捨 656, kidnap, 拐 657, pinch, 摘 658, challenge, 挑 659, finger, 指 660, hold, 持 661, fasten, 括 662, brandish, 揮 663, conjecture, 推 664, hoist, 揚 665, propose, 提 666, damage, 損 667, pick up, 拾 668, shouldering, 担 669, foothold, 拠 670, sketch, 描 671, maneuver, 操 672, touch, 接 673, put up a notice, 掲 674, hang, 掛 675, polish, 研 676, commandment, 戒 677, contraption, 械 678, nose, 鼻 679, punish, 刑 680, mould, 型 681, genius, 才 682, property, 財 683, lumber, 材 684, suppose, 存 685, exist, 在 686, from, 乃 687, portable, 携 688, reach out, 及 689, suck, 吸 690, handle, 扱 691, length, 丈 692, history, 史 693, officer, 吏 694, grow late, 更 695, stiff, 硬 696, or again, 又 697, pair, 双 698, mulberry, 桑 699, vessels, 隻 700, safeguard, 護 701, seize, 獲 702, guy, 奴 703, angry, 怒 704, friend, 友 705, slip out, 抜 706, throw, 投 707, drown, 没 708, establishment, 設 709, beat, 撃 710, husk, 殻 711, branch, 支 712, skill, 技 713, bough, 枝 714, limb, 肢 715, stalk, 茎 716, suspicious, 怪 717, lightly, 軽 718, uncle, 叔 719, coach, 督 720, loneliness, 寂 721, graceful, 淑 722, anti-, 反 723, slope, 坂 724, plank, 板 725, return, 返 726, marketing, 販 727, claw, 爪 728, gentle, 妥 729, milk, 乳 730, floating, 浮 731, leader, 将 732, exhort, 奨 733, pick, 採 734, vegetable, 菜 735, accept, 受 736, impart, 授 737, love, 愛 738, pay, 払 739, wide, 広 740, broaden, 拡 741, mineral, 鉱 742, valve, 弁 743, male, 雄 744, pedestal, 台 745, neglect, 怠 746, reign, 治 747, commence, 始 748, womb, 胎 749, window, 窓 750, gone, 去 751, method, 法 752, meeting, 会 753, climax, 至 754, room, 室 755, arrival, 到 756, doth, 致 757, mutually, 互 758, abandon, 棄 759, bring up, 育 760, remove, 撤 761, allot, 充 762, gun, 銃 763, sulfur, 硫 764, current, 流 765, license, 允 766, tempt, 唆 767, exit, 出 768, mountain, 山 769, bungling, 拙 770, boulder, 岩 771, charcoal, 炭 772, branch off, 岐 773, mountain pass, 峠 774, crumble, 崩 775, secrecy, 密 776, honey, 蜜 777, storm, 嵐 778, promontory, 崎 779, enter, 入 780, crowded, 込 781, part, 分 782, poverty, 貧 783, partition, 頒 784, public, 公 785, pine tree, 松 786, venerable old man, 翁 787, sue, 訟 788, valley, 谷 789, bathe, 浴 790, contain, 容 791, melt, 溶 792, longing, 欲 793, abundant, 裕 794, lead (metal), 鉛 795, run alongside, 沿 796, prize, 賞 797, party, 党 798, hall, 堂 799, usual, 常 800, skirt, 裳 801, manipulate, 掌 802, pelt, 皮 803, waves, 波 804, old woman, 婆 805, expose, 披 806, rend, 破 807, incur, 被 808, remainder, 残 809, martyrdom, 殉 810, particularly, 殊 811, augment, 殖 812, file, 列 813, split, 裂 814, ardent, 烈 815, death, 死 816, interment, 葬 817, wink, 瞬 818, ear, 耳 819, take, 取 820, gist, 趣 821, utmost, 最 822, snapshot, 撮 823, shame, 恥 824, post, 職 825, holy, 聖 826, daring, 敢 827, listen, 聴 828, pocket, 懐 829, ridicule, 慢 830, loose, 漫 831, buy, 買 832, placement, 置 833, penalty, 罰 834, rather, 寧 835, voiced, 濁 836, ring, 環 837, send back, 還 838, husband, 夫 839, aid, 扶 840, mountain stream, 渓 841, standard, 規 842, exchange, 替 843, approve, 賛 844, submerge, 潜 845, lose, 失 846, iron, 鉄 847, alternate, 迭 848, retainer, 臣 849, princess, 姫 850, storehouse, 蔵 851, entrails, 臓 852, intelligent, 賢 853, strict, 堅 854, look to, 臨 855, perusal, 覧 856, gigantic, 巨 857, repel, 拒 858, power, 力 859, man, 男 860, labor, 労 861, recruit, 募 862, inferiority, 劣 863, achievement, 功 864, persuade, 勧 865, toil, 努 866, encourage, 励 867, add, 加 868, congratulations, 賀 869, erect, 架 870, armpit, 脇 871, threaten, 脅 872, co-, 協 873, going, 行 874, rhythm, 律 875, restore, 復 876, gain, 得 877, accompany, 従 878, junior, 徒 879, wait, 待 880, journey, 往 881, subjugate, 征 882, diameter, 径 883, he, 彼 884, duty, 役 885, benevolence, 徳 886, penetrate, 徹 887, indications, 徴 888, penal, 懲 889, delicate, 微 890, boulevard, 街 891, equilibrium, 衡 892, draft, 稿 893, earnings, 稼 894, extent, 程 895, tax, 税 896, immature, 稚 897, harmony, 和 898, shift, 移 899, second, 秒 900, autumn, 秋 901, distress, 愁 902, private, 私 903, regularity, 秩 904, secret, 秘 905, appellation, 称 906, profit, 利 907, pear tree, 梨 908, harvest, 穫 909, ear of a plant, 穂 910, rice plant, 稲 911, incense, 香 912, seasons, 季 913, committee, 委 914, excel, 秀 915, transparent, 透 916, entice, 誘 917, cereals, 穀 918, germ, 菌 919, rice, 米 920, flour, 粉 921, sticky, 粘 922, grains, 粒 923, cosmetics, 粧 924, astray, 迷 925, chic, 粋 926, provisions, 糧 927, chrysanthemum, 菊 928, core, 奥 929, number, 数 930, watchtower, 楼 931, sort, 類 932, lacquer, 漆 933, Esq., 様 934, request, 求 935, ball, 球 936, salvation, 救 937, bamboo, 竹 938, laugh, 笑 939, bamboo hat, 笠 940, bamboo grass, 笹 941, muscle, 筋 942, box, 箱 943, writing brush, 筆 944, cylinder, 筒 945, etc., 等 946, calculate, 算 947, solution, 答 948, scheme, 策 949, register, 簿 950, fabricate, 築 951, person, 人 952, assistant, 佐 953, however, 但 954, dwell, 住 955, rank, 位 956, go-between, 仲 957, body, 体 958, remote, 悠 959, affair, 件 960, attend, 仕 961, other, 他 962, prostrated, 伏 963, transmit, 伝 964, Buddha, 仏 965, rest, 休 966, provisional, 仮 967, chief, 伯 968, vulgar, 俗 969, faith, 信 970, excellent, 佳 971, reliant, 依 972, example, 例 973, individual, 個 974, healthy, 健 975, side, 側 976, waiter, 侍 977, halt, 停 978, price, 値 979, emulate, 倣 980, overthrow, 倒 981, spy, 偵 982, Buddhist priest, 僧 983, hundred million, 億 984, ceremony, 儀 985, reparation, 償 986, hermit, 仙 987, sponsor, 催 988, humanity, 仁 989, scorn, 侮 990, use, 使 991, convenience, 便 992, double, 倍 993, tenderness, 優 994, fell, 伐 995, inn, 宿 996, wound, 傷 997, protect, 保 998, praise, 褒 999, greatness, 傑 1000, adhere, 付 1001, token, 符 1002, municipality, 府 1003, responsibility, 任 1004, fare, 賃 1005, substitute, 代 1006, sack, 袋 1007, lend, 貸 1008, change, 化 1009, flower, 花 1010, freight, 貨 1011, lean, 傾 1012, what, 何 1013, baggage, 荷 1014, sagacious, 俊 1015, bystander, 傍 1016, long time, 久 1017, furrow, 畝 1018, captured, 囚 1019, inside, 内 1020, third class, 丙 1021, design, 柄 1022, meat, 肉 1023, rot, 腐 1024, sit, 座 1025, graduate, 卒 1026, umbrella, 傘 1027, monme, 匁 1028, by means of, 以 1029, similar, 似 1030, join, 併 1031, tile, 瓦 1032, flower pot, 瓶 1033, Shinto shrine, 宮 1034, occupation, 営 1035, virtuous, 善 1036, year, 年 1037, night, 夜 1038, fluid, 液 1039, hillock, 塚 1040, cash, 幣 1041, abuse, 弊 1042, yell, 喚 1043, interchange, 換 1044, dissolve, 融 1045, alms, 施 1046, rotation, 旋 1047, play, 遊 1048, trip, 旅 1049, not, 勿 1050, thing, 物 1051, easy, 易 1052, grant, 賜 1053, urine, 尿 1054, nun, 尼 1055, mud, 泥 1056, fence, 塀 1057, footgear, 履 1058, roof, 屋 1059, grip, 握 1060, yield, 屈 1061, dig, 掘 1062, ditch, 堀 1063, reside, 居 1064, set, 据 1065, stratum, 層 1066, bureau, 局 1067, slow, 遅 1068, leak, 漏 1069, printing, 刷 1070, shaku, 尺 1071, exhaust, 尽 1072, swamp, 沢 1073, translate, 訳 1074, choose, 択 1075, daytime, 昼 1076, door, 戸 1077, shoulder, 肩 1078, tassel, 房 1079, fan, 扇 1080, hearth, 炉 1081, re-, 戻 1082, tears, 涙 1083, employ, 雇 1084, look back, 顧 1085, disclose, 啓 1086, show, 示 1087, salutation, 礼 1088, auspicious, 祥 1089, celebrate, 祝 1090, blessing, 福 1091, welfare, 祉 1092, company, 社 1093, inspection, 視 1094, Nara, 奈 1095, military officer, 尉 1096, consolation, 慰 1097, goodwill, 款 1098, prohibition, 禁 1099, collar, 襟 1100, religion, 宗 1101, adore, 崇 1102, ritual, 祭 1103, guess, 察 1104, grate, 擦 1105, wherefore, 由 1106, pluck, 抽 1107, oil, 油 1108, sleeve, 袖 1109, mid-air, 宙 1110, deliver, 届 1111, flute, 笛 1112, axis, 軸 1113, armor, 甲 1114, push, 押 1115, headland, 岬 1116, insert, 挿 1117, speaketh, 申 1118, expand, 伸 1119, gods, 神 1120, search, 捜 1121, fruit, 果 1122, confectionary, 菓 1123, chapter, 課 1124, naked, 裸 1125, ax, 斤 1126, chop, 析 1127, place, 所 1128, pray, 祈 1129, near, 近 1130, fold, 折 1131, philosophy, 哲 1132, departed, 逝 1133, vow, 誓 1134, temporarily, 暫 1135, steadily, 漸 1136, severance, 断 1137, substance, 質 1138, reject, 斥 1139, accusation, 訴 1140, yesterday, 昨 1141, lie, 詐 1142, make, 作 1143, snow, 雪 1144, record, 録 1145, inquire, 尋 1146, hurry, 急 1147, calm, 穏 1148, encroach, 侵 1149, immersed, 浸 1150, lie down, 寝 1151, lady, 婦 1152, sweep, 掃 1153, hit, 当 1154, contend, 争 1155, clean, 浄 1156, matter, 事 1157, T'ang, 唐 1158, sugar, 糖 1159, sane, 康 1160, apprehend, 逮 1161, Italy, 伊 1162, old boy, 君 1163, flock, 群 1164, -proof, 耐 1165, demand, 需 1166, Confucian, 儒 1167, edge, 端 1168, both, 両 1169, full, 満 1170, brush stroke, 画 1171, tooth, 歯 1172, bend, 曲 1173, cadet, 曹 1174, encounter, 遭 1175, rowing, 漕 1176, vat, 槽 1177, Big Dipper, 斗 1178, fee, 料 1179, department, 科 1180, map, 図 1181, utilize, 用 1182, comfortable, 庸 1183, equip, 備 1184, once upon a time, 昔 1185, confused, 錯 1186, borrow, 借 1187, pity, 惜 1188, set aside, 措 1189, scatter, 散 1190, twenty, 廿 1191, commoner, 庶 1192, intercept, 遮 1193, seat, 席 1194, degrees, 度 1195, transit, 渡 1196, bustle, 奔 1197, erupt, 噴 1198, tomb, 墳 1199, aroused, 憤 1200, bake, 焼 1201, daybreak, 暁 1202, half, 半 1203, consort, 伴 1204, paddy ridge, 畔 1205, judgment, 判 1206, ticket, 券 1207, scroll, 巻 1208, sphere, 圏 1209, victory, 勝 1210, wisteria, 藤 1211, facsimilie, 謄 1212, one-sided, 片 1213, printing block, 版 1214, of, 之 1215, destitution, 乏 1216, turf, 芝 1217, negative, 不 1218, negate, 否 1219, cupfuls, 杯 1220, dart, 矢 1221, rectify, 矯 1222, tribe, 族 1223, know, 知 1224, wisdom, 智 1225, halberd, 矛 1226, tender, 柔 1227, task, 務 1228, fog, 霧 1229, squad, 班 1230, homecoming, 帰 1231, bow, 弓 1232, pull, 引 1233, condolences, 弔 1234, vast, 弘 1235, strong, 強 1236, weak, 弱 1237, seethe, 沸 1238, expense, 費 1239, No., 第 1240, younger brother, 弟 1241, adroit, 巧 1242, nickname, 号 1243, decay, 朽 1244, boast, 誇 1245, dirty, 汚 1246, bestow, 与 1247, copy, 写 1248, somebody, 身 1249, shoot, 射 1250, apologize, 謝 1251, old man, 老 1252, consider, 考 1253, filial piety, 孝 1254, teach, 教 1255, torture, 拷 1256, someone, 者 1257, boil, 煮 1258, renowned, 著 1259, signature, 署 1260, sultry, 暑 1261, various, 諸 1262, boar, 猪 1263, strand, 渚 1264, gamble, 賭 1265, gorge, 峡 1266, cramped, 狭 1267, sandwiched, 挟 1268, chase, 追 1269, expert, 師 1270, commander, 帥 1271, bureaucrat, 官 1272, coffin, 棺 1273, pipe, 管 1274, father, 父 1275, mingle, 交 1276, merit, 効 1277, contrast, 較 1278, exam, 校 1279, leg, 足 1280, stimulate, 促 1281, long-distance, 距 1282, path, 路 1283, dew, 露 1284, hop, 跳 1285, leap, 躍 1286, tread, 践 1287, step, 踏 1288, skeleton, 骨 1289, slippery, 滑 1290, marrow, 髄 1291, calamity, 禍 1292, whirlpool, 渦 1293, overdo, 過 1294, Heights, 阪 1295, Africa, 阿 1296, occasion, 際 1297, hinder, 障 1298, follow, 随 1299, auxiliary, 陪 1300, sunshine, 陽 1301, line up, 陳 1302, ward off, 防 1303, affixed, 附 1304, Inst., 院 1305, camp, 陣 1306, regiment, 隊 1307, crash, 墜 1308, descend, 降 1309, story, 階 1310, highness, 陛 1311, neighboring, 隣 1312, isolate, 隔 1313, conceal, 隠 1314, degenerate, 堕 1315, collapse, 陥 1316, hole, 穴 1317, empty, 空 1318, withdraw, 控 1319, stab, 突 1320, research, 究 1321, plug up, 窒 1322, stealth, 窃 1323, depression, 窪 1324, squeeze, 搾 1325, kiln, 窯 1326, hard up, 窮 1327, grope, 探 1328, deep, 深 1329, hill, 丘 1330, Point, 岳 1331, soldier, 兵 1332, seacoast, 浜 1333, thread, 糸 1334, weave, 織 1335, darning, 繕 1336, shrink, 縮 1337, luxuriant, 繁 1338, vertical, 縦 1339, line, 線 1340, tighten, 締 1341, fiber, 維 1342, gauze, 羅 1343, practice, 練 1344, thong, 緒 1345, continue, 続 1346, picture, 絵 1347, overall, 統 1348, strangle, 絞 1349, salary, 給 1350, entwine, 絡 1351, tie, 結 1352, end, 終 1353, class, 級 1354, chronicle, 紀 1355, crimson, 紅 1356, settlement, 納 1357, spinning, 紡 1358, distract, 紛 1359, introduce, 紹 1360, sutra, 経 1361, sire, 紳 1362, promise, 約 1363, dainty, 細 1364, accumulate, 累 1365, cord, 索 1366, general, 総 1367, cotton, 綿 1368, silk, 絹 1369, winding, 繰 1370, inherit, 継 1371, green, 緑 1372, affinity, 縁 1373, netting, 網 1374, tense, 緊 1375, purple, 紫 1376, truss, 縛 1377, straw rope, 縄 1378, infancy, 幼 1379, behind, 後 1380, faint, 幽 1381, how many, 幾 1382, mechanism, 機 1383, mysterious, 玄 1384, livestock, 畜 1385, amass, 蓄 1386, bowstring, 弦 1387, hug, 擁 1388, nourishing, 滋 1389, mercy, 慈 1390, magnet, 磁 1391, lineage, 系 1392, person in charge, 係 1393, grandchild, 孫 1394, suspend, 懸 1395, instead, 却 1396, shins, 脚 1397, wholesale, 卸 1398, honorable, 御 1399, clothing, 服 1400, fate, 命 1401, orders, 令 1402, zero, 零 1403, age, 齢 1404, cool, 冷 1405, jurisdiction, 領 1406, small bell, 鈴 1407, courage, 勇 1408, traffic, 通 1409, jump, 踊 1410, doubt, 疑 1411, mimic, 擬 1412, congeal, 凝 1413, pattern, 範 1414, crime, 犯 1415, unlucky, 厄 1416, dangerous, 危 1417, address, 宛 1418, arm, 腕 1419, garden, 苑 1420, grudge, 怨 1421, willow, 柳 1422, egg, 卵 1423, detain, 留 1424, trade, 貿 1425, stamp, 印 1426, entertain, 興 1427, sign of the bird, 酉 1428, sake, 酒 1429, bartending, 酌 1430, fermentation, 酵 1431, cruel, 酷 1432, repay, 酬 1433, dairy products, 酪 1434, vinegar, 酢 1435, drunk, 酔 1436, distribute, 配 1437, acid, 酸 1438, waver, 猶 1439, revered, 尊 1440, beans, 豆 1441, head, 頭 1442, short, 短 1443, bountiful, 豊 1444, drum, 鼓 1445, rejoice, 喜 1446, timber-trees, 樹 1447, dish, 皿 1448, blood, 血 1449, basin, 盆 1450, alliance, 盟 1451, steal, 盗 1452, warm, 温 1453, oversee, 監 1454, overflow, 濫 1455, specimen, 鑑 1456, fierce, 猛 1457, boom, 盛 1458, salt, 塩 1459, silver, 銀 1460, resentment, 恨 1461, root, 根 1462, instant, 即 1463, baron, 爵 1464, node, 節 1465, retreat, 退 1466, limit, 限 1467, eyeball, 眼 1468, good, 良 1469, melodious, 朗 1470, wandering, 浪 1471, daughter, 娘 1472, eat, 食 1473, meal, 飯 1474, drink, 飲 1475, hungry, 飢 1476, starve, 餓 1477, decorate, 飾 1478, Bldg., 館 1479, foster, 養 1480, sated, 飽 1481, previously, 既 1482, outline, 概 1483, rue, 慨 1484, even, 平 1485, call, 呼 1486, two-mat area, 坪 1487, evaluate, 評 1488, reap, 刈 1489, hope, 希 1490, villain, 凶 1491, bosom, 胸 1492, detach, 離 1493, kill, 殺 1494, genuine, 純 1495, dull, 鈍 1496, spicy, 辛 1497, resign, 辞 1498, catalpa, 梓 1499, superintend, 宰 1500, wall, 壁 1501, evade, 避 1502, new, 新 1503, firewood, 薪 1504, parent, 親 1505, happiness, 幸 1506, tenacious, 執 1507, report, 報 1508, shout, 叫 1509, twist, 糾 1510, income, 収 1511, lowly, 卑 1512, tombstone, 碑 1513, land, 陸 1514, intimate, 睦 1515, forces, 勢 1516, heat, 熱 1517, diamond, 菱 1518, mausoleum, 陵 1519, sign of the hog, 亥 1520, nucleus, 核 1521, engrave, 刻 1522, above-stated, 該 1523, censure, 劾 1524, mention, 述 1525, art, 術 1526, cold, 寒 1527, brew, 醸 1528, defer, 譲 1529, lot, 壌 1530, lass, 嬢 1531, poison, 毒 1532, elementary, 素 1533, barley, 麦 1534, blue, 青 1535, refined, 精 1536, solicit, 請 1537, feelings, 情 1538, clear up, 晴 1539, pure, 清 1540, quiet, 静 1541, blame, 責 1542, exploits, 績 1543, volume, 積 1544, bond, 債 1545, pickling, 漬 1546, surface, 表 1547, bag, 俵 1548, undefiled, 潔 1549, pledge, 契 1550, consume, 喫 1551, harm, 害 1552, control, 轄 1553, proportion, 割 1554, constitution, 憲 1555, life, 生 1556, star, 星 1557, surname, 姓 1558, sex, 性 1559, animal sacrifice, 牲 1560, products, 産 1561, hump, 隆 1562, summit, 峰 1563, sew, 縫 1564, worship, 拝 1565, longevity, 寿 1566, casting, 鋳 1567, enroll, 籍 1568, springtime, 春 1569, camellia, 椿 1570, peaceful, 泰 1571, play music, 奏 1572, reality, 実 1573, dedicate, 奉 1574, stipend, 俸 1575, rod, 棒 1576, discreet, 謹 1577, diligence, 勤 1578, Sino-, 漢 1579, sigh, 嘆 1580, difficult, 難 1581, splendor, 華 1582, droop, 垂 1583, drowsy, 睡 1584, spindle, 錘 1585, ride, 乗 1586, surplus, 剰 1587, now, 今 1588, include, 含 1589, versify, 吟 1590, wish, 念 1591, harp, 琴 1592, shade, 陰 1593, beforehand, 予 1594, preface, 序 1595, deposit, 預 1596, plains, 野 1597, concurrently, 兼 1598, dislike, 嫌 1599, sickle, 鎌 1600, self-effacing, 謙 1601, bargain, 廉 1602, west, 西 1603, value, 価 1604, need, 要 1605, loins, 腰 1606, ballot, 票 1607, drift, 漂 1608, signpost, 標 1609, chestnut, 栗 1610, transition, 遷 1611, capsize, 覆 1612, smoke, 煙 1613, south, 南 1614, camphor tree, 楠 1615, offering, 献 1616, gates, 門 1617, question, 問 1618, review, 閲 1619, clique, 閥 1620, interval, 間 1621, simplicity, 簡 1622, open, 開 1623, closed, 閉 1624, tower, 閣 1625, leisure, 閑 1626, hear, 聞 1627, wet, 潤 1628, column, 欄 1629, fight, 闘 1630, godown, 倉 1631, genesis, 創 1632, un-, 非 1633, haiku, 俳 1634, repudiate, 排 1635, sad, 悲 1636, guilt, 罪 1637, comrade, 輩 1638, front door, 扉 1639, marquis, 侯 1640, climate, 候 1641, decide, 決 1642, cheerful, 快 1643, admirable, 偉 1644, difference, 違 1645, horizontal, 緯 1646, defense, 衛 1647, Korea, 韓 1648, dry, 干 1649, liver, 肝 1650, publish, 刊 1651, sweat, 汗 1652, flats, 軒 1653, beach, 岸 1654, tree trunk, 幹 1655, potato, 芋 1656, eaves, 宇 1657, too much, 余 1658, exclude, 除 1659, gradually, 徐 1660, confer, 叙 1661, route, 途 1662, diagonal, 斜 1663, paint, 塗 1664, bundle, 束 1665, trust, 頼 1666, rapids, 瀬 1667, imperial order, 勅 1668, alienate, 疎 1669, quick, 速 1670, organize, 整 1671, saber, 剣 1672, precipitous, 険 1673, examination, 検 1674, frugal, 倹 1675, heavy, 重 1676, move, 動 1677, meritorious deed, 勲 1678, work, 働 1679, species, 種 1680, collide, 衝 1681, fragrant, 薫 1682, ill, 病 1683, stupid, 痴 1684, pox, 痘 1685, symptoms, 症 1686, rapidly, 疾 1687, diarrhea, 痢 1688, tired, 疲 1689, epidemic, 疫 1690, pain, 痛 1691, mannerism, 癖 1692, hide, 匿 1693, artisan, 匠 1694, doctor, 医 1695, equal, 匹 1696, ward, 区 1697, hinge, 枢 1698, assault, 殴 1699, Europe, 欧 1700, repress, 抑 1701, faceup, 仰 1702, welcome, 迎 1703, ascend, 登 1704, lucidity, 澄 1705, discharge, 発 1706, abolish, 廃 1707, colleague, 僚 1708, dormitory, 寮 1709, heal, 療 1710, carve, 彫 1711, shape, 形 1712, shadow, 影 1713, cedar, 杉 1714, coloring, 彩 1715, patent, 彰 1716, lad, 彦 1717, face, 顔 1718, ought, 須 1719, swell, 膨 1720, visit, 参 1721, wretched, 惨 1722, discipline, 修 1723, rare, 珍 1724, checkup, 診 1725, sentence, 文 1726, vis-a-vis, 対 1727, family crest, 紋 1728, mosquito, 蚊 1729, adjusted, 斉 1730, dose, 剤 1731, finish, 済 1732, purification, 斎 1733, solemn, 粛 1734, bases, 塁 1735, music, 楽 1736, medicine, 薬 1737, ratio, 率 1738, astringent, 渋 1739, vicarious, 摂 1740, center, 央 1741, England, 英 1742, reflect, 映 1743, red, 赤 1744, pardon, 赦 1745, unusual, 変 1746, tracks, 跡 1747, barbarian, 蛮 1748, romance, 恋 1749, gulf, 湾 1750, yellow, 黄 1751, sideways, 横 1752, grasp, 把 1753, color, 色 1754, discontinue, 絶 1755, glossy, 艶 1756, fertilizer, 肥 1757, sweet, 甘 1758, navy blue, 紺 1759, so-and-so, 某 1760, conspire, 謀 1761, mediator, 媒 1762, deceit, 欺 1763, chess piece, 棋 1764, national flag, 旗 1765, period, 期 1766, Go, 碁 1767, fundamentals, 基 1768, tremendously, 甚 1769, intuition, 勘 1770, withstand, 堪 1771, precious, 貴 1772, bequeath, 遺 1773, dispatch, 遣 1774, dance, 舞 1775, nothingness, 無 1776, association, 組 1777, coarse, 粗 1778, tariff, 租 1779, ancestor, 祖 1780, thwart, 阻 1781, investigate, 査 1782, help, 助 1783, best regards, 宜 1784, tatami mat, 畳 1785, row, 並 1786, universal, 普 1787, musical score, 譜 1788, damp, 湿 1789, appear, 顕 1790, slender, 繊 1791, spirits, 霊 1792, profession, 業 1793, slap, 撲 1794, me, 僕 1795, together, 共 1796, submit, 供 1797, uncommon, 異 1798, wing, 翼 1799, deluge, 洪 1800, harbor, 港 1801, outburst, 暴 1802, bomb, 爆 1803, respect, 恭 1804, elect, 選 1805, Mr., 殿 1806, well, 井 1807, surround, 囲 1808, till, 耕 1809, Asia, 亜 1810, bad, 悪 1811, circle, 円 1812, angle, 角 1813, contact, 触 1814, unravel, 解 1815, again, 再 1816, lecture, 講 1817, subscription, 購 1818, posture, 構 1819, gutter, 溝 1820, argument, 論 1821, ethics, 倫 1822, wheel, 輪 1823, partial, 偏 1824, everywhere, 遍 1825, compilation, 編 1826, tome, 冊 1827, code, 典 1828, family name, 氏 1829, paper, 紙 1830, marriage, 婚 1831, lower, 低 1832, resist, 抵 1833, bottom, 底 1834, people, 民 1835, sleep, 眠 1836, catch, 捕 1837, bay, 浦 1838, bullrush, 蒲 1839, shop, 舗 1840, supplement, 補 1841, residence, 邸 1842, enclosure, 郭 1843, county, 郡 1844, outskirts, 郊 1845, section, 部 1846, metropolis, 都 1847, mail, 郵 1848, home country, 邦 1849, hometown, 郷 1850, echo, 響 1851, son, 郎 1852, corridor, 廊 1853, shield, 盾 1854, sequential, 循 1855, faction, 派 1856, vein, 脈 1857, masses, 衆 1858, parcel post, 逓 1859, grade, 段 1860, forge, 鍛 1861, empress, 后 1862, phantasm, 幻 1863, director, 司 1864, pay respects, 伺 1865, parts of speech, 詞 1866, domesticate, 飼 1867, heir, 嗣 1868, boat, 舟 1869, liner, 舶 1870, navigate, 航 1871, carrier, 般 1872, tray, 盤 1873, conveyor, 搬 1874, ship, 船 1875, warship, 艦 1876, rowboat, 艇 1877, melon, 瓜 1878, arc, 弧 1879, orphan, 孤 1880, cocoon, 繭 1881, benefit, 益 1882, spare time, 暇 1883, spread, 敷 1884, come, 来 1885, spirit, 気 1886, vapor, 汽 1887, fly, 飛 1888, sink, 沈 1889, wife, 妻 1890, decline, 衰 1891, inmost, 衷 1892, mask, 面 1893, leather, 革 1894, shoes, 靴 1895, hegemony, 覇 1896, voice, 声 1897, give, 呉 1898, recreation, 娯 1899, mistake, 誤 1900, steam, 蒸 1901, acquiesce, 承 1902, bin, 函 1903, poles, 極 1904, tusk, 牙 1905, bud, 芽 1906, wicked, 邪 1907, gracious, 雅 1908, interpretation, 釈 1909, turn, 番 1910, hearing, 審 1911, flip, 翻 1912, clan, 藩 1913, fur, 毛 1914, decrease, 耗 1915, tail, 尾 1916, home, 宅 1917, consign, 託 1918, do, 為 1919, falsehood, 偽 1920, long, 長 1921, lengthen, 張 1922, notebook, 帳 1923, dilate, 脹 1924, hair of the head, 髪 1925, unfold, 展 1926, miss, 喪 1927, nest, 巣 1928, simple, 単 1929, war, 戦 1930, Zen, 禅 1931, bullet, 弾 1932, cherry tree, 桜 1933, animal, 獣 1934, brain, 脳 1935, trouble, 悩 1936, stern, 厳 1937, chain, 鎖 1938, raise, 挙 1939, reputation, 誉 1940, game hunting, 猟 1941, bird, 鳥 1942, chirp, 鳴 1943, crane, 鶴 1944, crow, 烏 1945, vine, 蔦 1946, pigeon, 鳩 1947, chicken, 鶏 1948, island, 島 1949, warmth, 暖 1950, beautiful woman, 媛 1951, abet, 援 1952, slacken, 緩 1953, belong, 属 1954, entrust, 嘱 1955, accidentally, 偶 1956, interview, 遇 1957, foolish, 愚 1958, corner, 隅 1959, inverted, 逆 1960, model, 塑 1961, Mount, 岡 1962, steel, 鋼 1963, hawser, 綱 1964, sturdy, 剛 1965, tin can, 缶 1966, pottery, 陶 1967, swing, 揺 1968, Noh chanting, 謡 1969, concerning, 就 1970, sociable, 懇 1971, groundbreaking, 墾 1972, excuse, 免 1973, elude, 逸 1974, nightfall, 晩 1975, exertion, 勉 1976, elephant, 象 1977, statue, 像 1978, horse, 馬 1979, pony, 駒 1980, verification, 験 1981, equestrian, 騎 1982, parking, 駐 1983, drive, 駆 1984, station, 駅 1985, boisterous, 騒 1986, burdensome, 駄 1987, wonder, 驚 1988, fervent, 篤 1989, inflation, 騰 1990, tiger, 虎 1991, captive, 虜 1992, skin, 膚 1993, void, 虚 1994, frolic, 戯 1995, uneasiness, 虞 1996, prudence, 慮 1997, drama, 劇 1998, tyrannize, 虐 1999, deer, 鹿 2000, recommend, 薦 2001, jubilation, 慶 2002, lovely, 麗 2003, bear, 熊 2004, ability, 能 2005, attitude, 態 2006, sign of the tiger, 寅 2007, performance, 演 2008, sign of the dragon, 辰 2009, embarrass, 辱 2010, quake, 震 2011, shake, 振 2012, with child, 娠 2013, lips, 唇 2014, agriculture, 農 2015, concentrated, 濃 2016, send off, 送 2017, connection, 関 2018, blossom, 咲 2019, ghost, 鬼 2020, ugly, 醜 2021, soul, 魂 2022, witch, 魔 2023, fascination, 魅 2024, clod, 塊 2025, attack, 襲 2026, upbraid, 嚇 2027, majestic plural, 朕 2028, atmosphere, 雰 2029, item, 箇 2030, tempering, 錬 2031, abide by, 遵 2032, quit, 罷 2033, barracks, 屯 2034, moreover, 且 2035, seaweed, 藻 2036, slave, 隷 2037, healing, 癒 2038, cinnabar, 丹 2039, lagoon, 潟 2040, sign of the cow, 丑 2041, sign of the hare, 卯 2042, sign of the snake, 巳 """ IX_KANJI = 2 IX_KEYWORD = 1 kanji2kw = {} for line in StringIO(HEISIG): line = line.strip() parts = [ x.strip() for x in line.split(',') ] if len(parts) != 3: continue kanji2kw[parts[IX_KANJI]] = parts[IX_KEYWORD] STYLE = base64.decodestring(""" ICAgIGJvZHkgewogICAgICAgYmFja2dyb3VuZDogd2hpdGU7CiAgICAgICBjb2xvcjogYmxhY2s7 CiAgICAgICBmb250LWZhbWlseTogTHVjaWRhVHlwZXdyaXRlciwgTHVjaWRhIENvbnNvbGUsIE1v bmFjbywgVGVybWluYWwsIENvdXJpZXIsIG1vbm9zcGFjZSwgc2Fuc3NlcmlmOwogICAgICAgZm9u dC1zaXplOiAxMnB4OwogICAgICAgbWFyZ2luOiAxMHB4OwogICAgfQoKICAgIGgxLGgyLGgzIHsK ICAgICAgIGZvbnQtd2VpZ2h0OmJvbGQ7CiAgICAgICBmb250LXNpemU6MTRweDsKICAgICAgIG1h cmdpbi10b3A6MTRweDsKICAgICAgIG1hcmdpbi1ib3R0b206NXB4OwogICAgICAgcGFkZGluZzow OwogICAgfQogICAgc3Bhbi50YWcgewogICAgICBjb2xvcjogcmVkOwogICAgICBiYWNrZ3JvdW5k OiByZ2IoMjM4LCAyMzgsIDApOwogICAgICBmb250LXNpemU6IHNtYWxsCiAgICB9CiAgICBiIHsK ICAgIGZvbnQtZmFtaWx5OiBWZXJkYW5hLCBBcmlhbCwgSGVsdmV0aWNhLCBzYW5zLXNlcmlmOwog ICAgZm9udC1zaXplOiAxMnB4OwogICAgZm9udC13ZWlnaHQ6IGJvbGQ7CiAgICBtYXJnaW4tbGVm dDogNHB4OyAKICAgIH0K""") APP_TITLE = 'Heisig Lookup' def genpage(args=None): yield '' yield '' yield '' yield '%s' % APP_TITLE yield '' yield '' yield '

%s

' % APP_TITLE yield '
' yield '' yield '' yield '
' if args: kanji = urllib.unquote(args) yield 'Text: %s
' % kanji for x in unicode(kanji, 'utf-8'): k = x.encode('utf-8') yield k kw = kanji2kw.get(k) if kw: yield '[%s] ' % kw yield '' yield '' class HTTPServer(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): if self.path.startswith('/favicon.ico'): # annoying, simply annoying! self.ok(404, {'Content-type': 'text/html'}, 'wtf?') elif self.path.startswith('/?decode='): self.ok(200, {'Content-type': 'text/html; charset=utf-8'}, genpage(self.path[9:])) else: self.ok(200, {'Content-type': 'text/html'}, genpage()) def ok(self, code, headers, data): self.send_response(code) for header in headers.keys(): self.send_header(header, headers[header]) self.end_headers() def flatten(input): for x in input: if not isinstance(x, types.GeneratorType): yield x else: for y in flatten(x): yield y if data: for x in flatten(data): self.wfile.write(x) if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() parser.add_option('-p','--port', type='int', dest='port', help='server port', default=8080) (options, args) = parser.parse_args() try: addr = ('', options.port) httpd = BaseHTTPServer.HTTPServer(addr, HTTPServer) print >> sys.stderr, 'Serving on %s:%s' % httpd.socket.getsockname() httpd.serve_forever() except KeyboardInterrupt: print 'Keyboard interrupt'