1 Star 0 Fork 6

morcc/stata_ado

forked from songbl/stata_ado 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
songbl.ado 59.26 KB
一键复制 编辑 原始数据 按行查看 历史
松柏林 提交于 2021-05-12 14:12 . update songbl.ado
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
*Inspirit of -lianxh-(Yujun, Lian*;Junjie, Kang;Qingqing, Liu)
* Authors:
* Program written by Bolin, Song (松柏林) Shenzhen University , China.
* Wechat:songbl_stata
* Please do not use this code for commerical purpose
*Songbl makes it easy for users to search and open thousands of Stata blog posts and useful Stata information in Stata window. You can also browse the papers and replication data & programs etc of China's industrial economy by category.
capture program drop songbl
program define songbl
version 14
syntax [anything(name = class)] ///
[, ///
Mlink /// // - [推文标题](URL)
MText /// // [推文标题](URL)
MUrl /// // n. [推文标题](URL)
Wlink /// // 推文标题: URL
WText /// // 推文标题: URL
WUrl /// // n. 推文标题: URL
NOCat /// // 不呈现推文分类信息
Paper /// // 搜索论文。
Cls /// // 清屏后显示结果
Gap /// // 在输出的结果推文之间进行空格一行
File(string) /// // 括号内为文档类型,包括 do 、pdf。
Type(string) /// // 按照推文来源进行检索。
Navigation /// // 导航功能
TIme /// // 输出检索结果的末尾带有返回推文分类目录或者论文分类目录的快捷方式
SAVE(string) /// // 利用文档打开分享的内容。
REPLACE /// // 生成分享内容的 STATA 数据集。
So /// // 网页搜索功能快捷方式
Sou(string) /// // 网页搜索功能
Num(numlist integer max=1 min=1 >0 ) ///
Line ///
]
tokenize `class'
*
*==============================================================================*
*==============================================================================*
* 预先设定option
* "sou" options识别
if "`sou'"!=""{
*local sou =subinstr("`sou'"," ","",.)
local class=stritrim("`class'")
tokenize `sou'
local 1=ustrleft("`1'",1)
if strmatch("计量圈","*`1'*")==1 | "`sou'"=="q"{
view browse "https://data.newrank.cn/m/s.html?s=OjAqNjI2LjxI&k=`class'"
exit
}
else if strmatch("百度","*`1'*")==1 | "`sou'"=="b"{
view browse "https://www.baidu.com/s?&wd=`class'"
exit
}
else if strmatch("微信公众号","*`1'*")==1 | "`sou'"=="w"{
view browse "https://weixin.sogou.com/weixin?type=2&query=`class'"
exit
}
else if strmatch("经管之家","*`1'*")==1 | "`sou'"=="j"{
view browse "http://sou.pinggu.org/cse/search?q=`class'&s=4433512227215735158&nsid=0"
exit
}
else if strmatch("知乎","*`1'*")==1 | "`sou'"=="z"{
view browse "https://www.zhihu.com/search?type=content&q=`class'"
exit
}
else if strmatch("全部","*`1'*")==1 | "`sou'"=="all" {
view browse "https://data.newrank.cn/m/s.html?s=OjAqNjI2LjxI&k=`class'"
view browse "https://www.baidu.com/s?&wd=`class'"
view browse "https://weixin.sogou.com/weixin?type=2&query=`class'"
view browse "http://sou.pinggu.org/cse/search?q=`class'&s=4433512227215735158&nsid=0"
view browse "https://www.zhihu.com/search?type=content&q=`class'"
exit
}
else {
dis as error `" (`sou') 不是正确的搜索来源,仅包括计量圈、百度、微信公众号、经管之家、知乎"'
dis as text _n `" 试试:"'
dis as text _col(5)`" {stata " songbl `class',s(计量圈) "} 或 {stata " songbl `class',s(百度) "}"' _n
dis as text _col(5)`" {stata " songbl `class',s(公众号) "} 或 {stata " songbl `class',s(知乎) "}"' _n
dis as text _col(5)`" {stata " songbl `class',s(经管家) "} 或 {stata " songbl `class',s(全部) "}"' _n
exit
}
}
if "`so'"!=""{
dis as text
dis as text _col(5)`" {stata " songbl `*',s(计量圈) "} 或 {stata " songbl `*',s(百度) "}"' _n
dis as text _col(5)`" {stata " songbl `*',s(公众号) "} 或 {stata " songbl `*',s(知乎) "}"' _n
dis as text _col(5)`" {stata " songbl `*',s(经管家) "} 或 {stata " songbl `*',s(全部) "}"' _n
exit
}
* "time" options识别
if "`time'"!=""{
timer clear 1
timer on 1
}
* "cls" options识别
if "`cls'" != ""{
cls
}
* "type" options识别
if "`class'"!="" {
if "`type'" == "lianxh" | "`type'" == "lxh" {
local type1 qui keep if type2==1
local type3 dis as text " 推文来源 >> 连享会"
}
if "`type'" == "sc" {
local type1 qui keep if type2==6
local type3 dis as text " 推文来源 >> 爬虫俱乐部"
}
if "`type'" == "paper" {
local type1 qui keep if type2==2 | type2==3
local type3 dis as text " 推文来源 >> 学术论文"
}
if "`type'" !="" & "`type'" != "lianxh" & "`type'" != "lxh" & "`type'" != "sc" & "`type'" != "paper" {
disp as error `" option type(`type') is error. 请点击{stata " help songbl"}"'
exit
}
}
* "gap" options识别
if "`gap'" != "" {
local gap dis ""
local gap1 post songbl_post ("" )
}
if ("`replace'"=="") {
preserve
}
clear // 避免变量与用户变量冲突
*
*==============================================================================*
*==============================================================================*
* 动态导航功能设置
* 分类查看所有推文
if "`class'"=="" {
tempfile html_text
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "5613B258C5FF441B901CD78CAFAE6D6C?method="
local http3 "download&shareKey=47627301c0a7cd1e39e2fe0577d1f10c"
local URL1 "`http1'`http2'`http3'"
local URL https://songbl-1304948727.cos.ap-guangzhou.myqcloud.com/navigation/songbl.txt
cap copy `"`URL'"' "`html_text'.txt", replace
if _rc ~= 0 {
local URL `URL1'
}
songbl_links ,url(`URL')
exit
}
* 知网经济学期刊导航
if "`class'"=="zw"{
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "466C2230BDBD4820A9851180AFCA64BC?method="
local http3 "download&shareKey=7cf2334a57eb484a478b5c5feeb3d18a"
local URL "`http1'`http2'`http3'"
songbl_links1 , url(`URL')
exit
}
* 分类查看所有论文
if "`class'"=="paper"{
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "0167308C0D354082998D0152DBD6703E?method="
local http3 "download&shareKey=872dfb4ae9e8e363e59dc551e8f594be"
local URL "`http1'`http2'`http3'"
songbl_links1 ,url(`URL')
exit
}
* 常用STATA与经济学网站
if "`class'"=="stata"{
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "7636593A108F4D2A8822E7FB559DF6A6?method="
local http3 "download&shareKey=f4b970a98aa619af543e79ff4856992c"
local URL "`http1'`http2'`http3'"
songbl_links1 , url(`URL')
exit
}
* 常用数据库网站
if "`class'"=="data"{
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "0CEDE9E94A1A48318974261726F9F048?method="
local http3 "download&shareKey=19fb9b5596d80cb85717cc210d7c9b81"
local URL "`http1'`http2'`http3'"
songbl_links ,url(`URL')
exit
}
* 功能导航
if "`class'"=="all"{
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "324DE307CAB2440CBC67CC318E9CEB45?method="
local http3 "download&shareKey=bc1dfb9cd7a3cde598aed799d10ec86b"
local URL "`http1'`http2'`http3'"
songbl_links1 , url(`URL')
exit
}
* 科研之余,消遣放松网站
if "`class'"=="music"{
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "1E6B86607C214BB79DBDCD957107B208?method="
local http3 "download&shareKey=fab80cea7b6883d16be1c5b795634d3e"
local URL "`http1'`http2'`http3'"
songbl_links ,url(`URL')
exit
}
*批量获取导航链接
if "`navigation'"!=""{
tempfile html_text
local http1 "https://note.youdao.com/yws/api/personal/file/"
local http2 "4DCA13297C1947E6BD85A9A14450B9BB?method="
local http3 "download&shareKey=2ac33ef51b54f89f15b8c71d252ba716"
local URL "`http1'`http2'`http3'"
local URL1 https://songbl-1304948727.cos.ap-guangzhou.myqcloud.com/songbl_URL.txt
cap copy `"`URL1'"' "`html_text'.txt", replace
if _rc ~= 0 {
cap copy `"`URL'"' "`html_text'.txt", replace
}
local times = 0
while _rc ~= 0 {
local times = `times' + 1
sleep 1000
cap copy `"`URL'"' "`html_text'.txt", replace
if `times' > 10 {
disp as error "Internet speeds is too low to get the data"
exit 601
}
}
qui infix strL v 1-100000 using "`html_text'.txt", clear
qui split v, p("++")
cap keep v1 v2 v3
local o_class= "`class'"
local class = lower("`class'")
qui levelsof v1 , local(v1_type) clean
if strmatch("`r(levels)'","*`class'*")==0{
dis as error `" 导航格式错误"'
dis as error `" 查看导航目录:{stata "songbl all"}"'
exit 601
}
local N=_N
forvalues i =1/`N'{
local v1_`i'=v1[`i']
local v2_`i'=v2[`i']
local v3_`i'=v3[`i']
if "`class'"=="`v1_`i''"{
local URL "`v3_`i''"
`v2_`i'' , url(`URL')
exit
}
}
exit
}
*
*==============================================================================*
*==============================================================================*
* 数据爬取与处理
*==============================================================================*
* 爬取文本数据保存为临时txt文件并导入Stata
qui{
* 推文链接与标题
local http "https://songbl-1304948727.cos.ap-guangzhou.myqcloud.com/"
local http1 "http://note.youdao.com/yws/api/personal/file/"
local http2 "FDF39DDFF4F047678A9C52FE24F2F054?method=download"
local http3 "&shareKey=5f6386bfc3519af602fd50cebf0ae642"
local stata_paper_youdao "`http1'`http2'`http3'"
local stata_paper_tengxun "`http'stata_paper.txt"
* 论文链接与标题。推文与论文分开放置有利于提高下载速度。
local http4 "DC8CC22ADC89489E8380E4C7829D3C74?method=download"
local http5 "&shareKey=302e182e47b5771a4ffd839e17544cec"
local paper_youdao "`http1'`http4'`http5'"
local paper_tengxun "`http'paper.txt"
tempfile html_text html_text_dta Share_txt songbl_post
* 推文链接文本下载
if missing("`paper'"){
cap copy `"`stata_paper_tengxun'"' "`html_text'.txt", replace
if _rc ~= 0 {
cap copy `"`stata_paper_youdao'"' "`html_text'.txt", replace
}
local times = 0
while _rc ~= 0 {
local times = `times' + 1
sleep 1000
cap copy `"`stata_paper_youdao'"' "`html_text'.txt", replace
if `times' > 10 {
disp as error "Internet speeds is too low to get the data"
exit 601
}
}
}
* 论文链接文本下载
else {
cap copy `"`paper_tengxun'"' "`html_text'.txt", replace
if _rc ~= 0 {
cap copy `"`paper_youdao'"' "`html_text'.txt", replace
}
local times = 0
while _rc ~= 0 {
local times = `times' + 1
sleep 1000
cap copy `"`paper_youdao'"' "`html_text'.txt", replace
if `times' > 10 {
disp as error "Internet speeds is too low to get the data"
exit 601
}
}
}
* 导入文本数据到stata
infix strL v 1-100000 using "`html_text'.txt", clear
split v, p("++")
*erase "`html_text'.txt"
if _rc ~= 0 {
di as err "Failed to get the data"
exit 601
}
*==============================================================================*
* 文本数据处理
* 变量重命名
rename v1 link //链接
rename v2 title //标题
rename v3 style //推文内容分类
rename v4 type //推文来源分类
rename v5 seminar_paper //推文来源分类
* 推文来源分类排序
gen type2=.
replace type2=1 if type=="连享会"
replace type2=2 if type=="学术论文"
replace type2=3 if type=="论文代码"
replace type2=4 if type=="do文档"
replace type2=5 if type=="微信公众号"
replace type2=6 if type=="爬虫俱乐部"
replace type2=7 if type=="经管之家"
replace type2=8 if type=="简书"
replace type2=9 if type=="知乎"
replace type2=10 if type=="B站"
replace type2=11 if type=="新浪博客"
replace type2=12 if type=="Stata书籍"
replace type2=13 if type=="其他类型"
* 后续检索关键词不区分大小写
local 11 = "`1'"
local 22 = "`2'"
local 33 = "`3'"
local 44 = "`4'"
local 55 = "`5'"
local 1 = strlower("`1'")
local 2 = strlower("`2'")
local 3 = strlower("`3'")
local 4 = strlower("`4'")
local 5 = strlower("`5'")
gen title1 = lower(title)
gen style1 = lower(style)
* 关键词"class"识别
gen yjy1 = strmatch(title1,"*`1'*")
gen yjy2 = strmatch(title1,"*`2'*")
gen yjy3 = strmatch(title1,"*`3'*")
gen yjy4 = strmatch(title1,"*`4'*")
gen yjy5 = strmatch(title1,"*`5'*")
gen y1 = strmatch(style1,"*`1'*")
gen y2 = strmatch(style1,"*`2'*")
gen y3 = strmatch(style1,"*`3'*")
gen y4 = strmatch(style1,"*`4'*")
gen y5 = strmatch(style1,"*`5'*")
gen ad = strmatch(type,"*ad*")
drop if style1=="未分类学术论文"
drop if seminar_paper=="ad"
replace seminar_paper="推文" if seminar_paper=="专题"
`type1' // 执行 type option
`type3'
}
*
*==============================================================================*
*==============================================================================*
* 当前日期转为通用年、月、日格式
local start: disp %dCYND date("`c(current_date)'","DMY")
local year = substr("`start'",1,4)
local month = substr("`start'",5,2)
local day = substr("`start'",7,2)
local cur_time "`year'""年""`month'""月""`day'""日"
local new_link =link[1]
local new_title =title[1]
qui drop in 1
*
*==============================================================================*
*==============================================================================*
* 关键词"class" 搜索
*------------------------------------------------------------------------*
***输入1个关键词***
if "`class'"=="公告" & "`paper'"=="" & "`wlink'" =="" & "`wtext'" =="" & "`mlink'" =="" ///
& "`mtext'" =="" & "`murl'" =="" & "`wurl'" =="" & "`replace'" =="" & "`save'" =="" {
dis as txt "{hline 110} "
dis in text _col(30) "{bf:致各位使用songbl命令的Stata爱好者的一份公告}"
dis as txt "{hline 110} "
dis ""
dis in text "{bf:命令介绍:}"
dis _col(6) in text "songbl是一个用于Stata资源共享与检索的命令"
dis _col(6) in text `"关于命令使用方式的详细介绍,请查看:{stata h songbl_cn: {bf:help songbl} }"' _n
dis ""
*dis _col(6) in text `"{bf:请注意:}"'
dis _col(6) in text `"为了扩大songbl命令的资源库;"' `"为了songbl命令的可持续发展;"' `"为了更好地促进stata知识交流"' _n
dis in text "{bf:我们倡议:}"
dis ""
dis _col(6) as red "{bf:凡是使用songbl命令的朋友,请务必通过下面的链接,每半年内至少分享一次资料或相关文章}" _n
dis _col(6) in text "资源包括:Stata推文、帖子、理论与实证论文、数据、视频或者其他资源"
dis _col(6) in text "资源发布后就可以在Stata窗口搜到,或者在Stata窗口输入:songbl new,n(#),查看最新上传的资源 "
dis _col(6) in text "songbl new 默认显示最新上传前10条资源。" "显示最新上传前20条资源则为:songbl new,n(20) " _n
dis _col(6) in text "上传资源到Songbl数据库的链接:" `"{browse "`new_link'": {bf:`new_link'}}"' _n
dis _col(6) in text "Distribution-Date: 20210512"
dis _col(6) in text "Author:Song Bolin,(松柏林)Shenzhen University, China."
dis _col(6) in text "Support: Stata微信交流群 " `"{browse "http://note.youdao.com/s/9TtkhFTJ":{bf:songbl_stata}}"'
dis as txt "{hline 110} "
dis as text _col(3) `"{stata songbl new,g: (查看最新上传Songbl平台的资源)}"' _n
exit
}
if "`1'"!="" & "`2'"=="" {
if "`1'"=="new" & "`paper'"=="" & "`wlink'" =="" & "`wtext'" =="" & "`mlink'" =="" ///
& "`mtext'" =="" & "`murl'" =="" & "`wurl'" =="" & "`replace'" =="" & "`save'" =="" {
*dingwei title,c(new_songbl) //定位今日更新推文的行号
* local nrow=-`num'
*local N=_N
if "`num'"==""{
local num=10
}
qui drop if strmatch(link,"* *")==1
qui drop if title=="new_songbl"
qui drop in 1
qui drop if seminar_paper=="论文"
qui drop if type=="ad"
qui cap keep in -`num'/ -1 //保留今日更新推文的行号 `nrow'/ `N'
*local nn=_N //今日更新推文共 n 行
local n=_N
dis as text _skip(45) "{bf:Hello, Songbl Stata}" _n
if `num'>`n'{
dis as text _col(4) "以下为全部推文:共`n'篇" _col(88) "`year'-`month'-`day' `c(current_time)'"
}
else{
dis as text _col(4) "以下为最新`num'篇推文" _col(88) "`year'-`month'-`day' `c(current_time)'"
}
dis as txt "{hline 110} "
*dis "{synoptline}"
dis _col(4) in text "{bf:分类}" _col(23) `"{bf:来源}"' _col(39) `"{bf:类型}"' _col(53) `"{bf:标题}"'
*dis "{synoptline}"
dis as txt "{hline 110} "
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
local type=type[`i']
local style=style[`i']
local seminar_paper =seminar_paper[`i']
*dis _col(4) `"{browse "`link'": `title'}"'
dis _col(3) `"{browse "`link'": `style'}"' _col(23) `"`type'"' _col(39) `"`seminar_paper'"' _col(53) `"`title'"'
*dis "{synoptline}"
if "`line'"!=""{
dis as txt "{hline 110} "
}
`gap'
}
*dis "{synoptline}"
if "`line'"==""{
dis as txt "{hline 110} "
}
dis as text _col(3) `"{stata songbl 公告: (Songbl平台公告与资源上传)}"' _n
exit
}
if "`1'"!="songbl" {
quietly keep if yjy1==1 | y1==1 | ad==1
}
}
*------------------------------------------------------------------------*
***输入2个关键词***
qui{
if "`2'"!="" & "`3'"=="" {
keep if (yjy1==1 | y1==1) & (yjy2==1 | y2==1) | ad==1
}
*------------------------------------------------------------------------*
***输入3个关键词***
if "`3'"!="" & "`4'"=="" {
if "`2'"=="-"{
keep if (yjy1==1 | y1==1) & (yjy3==0 & y3==0) | ad==1 //第二个关键词为 "-"
}
else if "`2'"=="+"{
keep if (yjy1==1 | y1==1) | (yjy3==1 | y3==1) | ad==1 //第二个关键词为 "+"
}
else {
keep if (yjy1==1 | y1==1) & (yjy2==1 | y2==1) & (yjy3==1 | y3==1) | ad==1 //其余情况
}
}
*------------------------------------------------------------------------*
***输入4个关键词***
if "`4'"!="" & "`5'"=="" {
if "`2'"=="+" {
keep if [(yjy1==1 | y1==1 ) | (yjy3==1 | y3==1)] & (yjy4==1 | y4==1) | ad==1 //第二个关键词为 "+"
}
else if "`2'"=="-" {
keep if (yjy1==1 | y1==1) & (yjy3==0 & y3==0) & (yjy4==1 | y4==1) | ad==1 //第二个关键词为 "-"
}
else if "`3'"=="+" {
keep if (yjy1==1 | y1==1) & (yjy2==1 | y2==1) | (yjy4==1 | y4==1) | ad==1 //第三个关键词为 "+"
}
else if "`3'"=="-" {
keep if (yjy1==1 | y1==1) & (yjy2==1 | y2==1) & (yjy4==0 & y4==0) | ad==1 //第三个关键词为 "-"
}
else {
keep if (yjy1==1 | y1==1) & (yjy2==1 | y2==1) & (yjy3==1 | y3==1) & (yjy4==1 | y4==1) | ad==1 //其余情况
}
}
}
if "`5'"!=""{
if strmatch("`class'","*+*")==1 | strmatch("`class'","*-*")==1{
dis as error `" "+" 或者 "-" 号,则最多仅能出现一次"'
}
else {
dis as error `"最多仅支持4个关键词搜索。"'
}
exit 198
}
qui drop if seminar_paper=="其他"
qui save "`html_text_dta'", replace // 保存关键词 "class" 搜索到的数据
local n =_N //排除无效数据
local ad =ad[1]
if _N==0|(_N==1 & `ad'==1){
if missing("`paper'"){
dis as error `"没有搜到{`*'}相关的推文。{stata "songbl": 点击分类查看推文}"'
}
else{
dis as error `"没有搜到{`*'}相关的论文。{stata "songbl paper": 点击分类查看论文}"'
}
cap erase "`html_text'.txt"
exit
}
*
*==============================================================================*
*==============================================================================*
* 关键词"class" 打印
if "`wlink'" =="" & "`wtext'" =="" & "`mlink'" =="" & "`mtext'" =="" & "`murl'" =="" & "`wurl'" =="" {
qui levelsof seminar_paper , local(seminar_paper)
foreach seminar_paper in `seminar_paper' {
use "`html_text_dta'", clear
qui keep if seminar_paper=="`seminar_paper'"
*dis "`seminar_paper '"
qui levelsof style , local(number)
foreach num in `number' {
qui keep if style=="`num'"
*local o_num="`num'"
*local num=subinstr("`num'"," ","",.)
local n=_N
if `n'>0{
if strmatch("`num'","*学术论文*") ==1 {
sort title
if missing("`nocat'"){
local name = plural(2,"`num'","-学术论文")
if missing("`paper'"){
dis as w " `seminar_paper' >>"`"{stata "songbl `name'": `name'}"'"
}
else{
dis as w " `seminar_paper' >>"`"{stata "songbl `name',paper": `name'}"'"
}
}
}
else {
sort type2 title
if missing("`nocat'"){
dis as w " `seminar_paper' >>"`"{stata "songbl `num'": `num'}"'"
}
}
if "`line'"!=""{
if missing("`nocat'"){
dis as txt "{hline 100} "
}
*dis "{synoptline}"
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
local type=type[`i']
local style=style[`i']
local seminar_paper =seminar_paper[`i']
dis _col(5) `"{browse "`link'":{bf:-}}"'_col(7) `"`title'"'
*if "`line'"!=""{
* dis as txt "{hline 100}"
* dis "{synoptline}"
*}
`gap'
}
*if "`line'"==""{
* dis as txt "{hline 100}"
* dis "{synoptline}"
*}
}
else{
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
if strmatch("`link'","* *")==1{
dis _col(4) `"{stata "`link'": `title'}"'
}
else{
dis _col(4) `"{browse "`link'": `title'}"'
}
if "`file'"!="" & strmatch("`title'", "*.`file'")==1 {
gitee "`link'",cla(`file')
}
`gap'
}
}
}
use "`html_text_dta'", clear
if missing("`nocat'"){
dis ""
}
}
}
if "`save'"!="" {
dis as error `" 命令格式有误,see { stata " help songbl_cn" }"'
dis as error `" Note:save 选择项必须与 wlink 、wtext 、mlink 、mtext、murl、wurl 等分享功能一起使用 "'
exit 198
}
}
else {
capture postclose songbl_post
qui postfile songbl_post str1000 Share using "`songbl_post'", replace
/*
if "`class'"=="new"{
local cur_time "`year'年`month'月`day'日"
post songbl_post (`"# **`cur_time' 更新了`nn'篇 STATA 推文** "')
}
*/
if "`wlink'" !=""{
dis ""
dis as txt _n "{hline 24} wlink文本格式 {hline 24}"
post songbl_post ("------------------------ wink文本格式 ------------------------")
dis as txt
post songbl_post (" ")
if missing("`paper'"){
dis as res "* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace"
dis as res "* 查看更多内容请在 STATA 窗口输入代码:songbl `class'"
post songbl_post ("* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace")
post songbl_post ("* 查看更多内容请在 STATA 窗口输入代码:songbl `class'")
}
else {
dis as res "* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace"
dis as res "* 查看更多内容请在 STATA 窗口输入代码:songbl `class',paper"
post songbl_post ("* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace")
post songbl_post ("* 查看更多内容请在 STATA 窗口输入代码:songbl `class',paper")
}
dis as txt
post songbl_post (" ")
qui levelsof seminar_paper , local(seminar_paper)
local m=_N
foreach seminar_paper in `seminar_paper' {
use "`html_text_dta'", clear
qui keep if seminar_paper=="`seminar_paper'"
qui levelsof style , local(number)
foreach num in `number' {
qui keep if style=="`num'"
local n=_N
if `n'>0{
if strmatch("`num'","*学术论文*") ==1 {
sort title
if missing("`nocat'"){
local name = plural(2,"`num'","-学术论文")
if missing("`paper'"){
dis as w _col(4) " 论文 >>"`"{stata "songbl `name'": `name'}"'"
post songbl_post (" 论文 >> `name'")
`gap'
`gap1'
}
else{
dis as w _col(4) " 论文 >>"`"{stata "songbl `name',paper": `name'}"'"
post songbl_post (" 论文 >> `name'")
`gap'
`gap1'
}
}
}
else {
sort type2 title
if missing("`nocat'"){
dis as w _col(4) " `seminar_paper' >>"`"{stata "songbl `num'": `num'}"'"
`gap'
`gap1'
post songbl_post (" `seminar_paper' >> `num'" )
}
}
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
dis as y "`title': `link'"
post songbl_post ("`title': `link'")
`gap'
`gap1'
}
}
use "`html_text_dta'", clear
if missing("`nocat'"){
dis ""
post songbl_post (" " )
}
}
}
dis ""
dis as txt "{hline 24} 分享复制以上内容 {hline 24}"
if `m'>=10{
dis in red _n "小提示:建议分多次复制到微信对话框,每次 10 行,否则超链接无法生效"
dis in red " 分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
else{
dis in red _n "小提示:分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
}
if "`wtext'" !=""{
dis ""
dis as txt _n "{hline 24} wtxt文本格式 {hline 24}"
post songbl_post ("------------------------ wtxt文本格式 ------------------------")
dis as txt
post songbl_post (" ")
if missing("`paper'"){
dis as res "* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace"
dis as res "* 查看更多内容请在 STATA 窗口输入代码:songbl `class'"
post songbl_post ("* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace")
post songbl_post ("* 查看更多内容请在 STATA 窗口输入代码:songbl `class'")
}
else {
dis as res "* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace"
dis as res "* 查看更多内容请在 STATA 窗口输入代码:songbl `class',paper"
post songbl_post ("* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace")
post songbl_post ("* 查看更多内容请在 STATA 窗口输入代码:songbl `class',paper")
}
dis as txt
post songbl_post (" ")
qui levelsof seminar_paper , local(seminar_paper)
local m=_N
foreach seminar_paper in `seminar_paper' {
use "`html_text_dta'", clear
qui keep if seminar_paper=="`seminar_paper'"
qui levelsof style , local(number)
foreach num in `number' {
qui keep if style=="`num'"
local n=_N
if `n'>0{
if strmatch("`num'","*学术论文*") ==1 {
sort title
if missing("`nocat'"){
local name = plural(2,"`num'","-学术论文")
if missing("`paper'"){
dis as w _col(4) " 论文 >>"`"{stata "songbl `name'": `name'}"'"
post songbl_post (" 论文 >> `name'")
`gap'
}
else{
dis as w _col(4) " 论文 >>"`"{stata "songbl `name',paper": `name'}"'"
post songbl_post (" 论文 >> `name'")
`gap'
`gap1'
}
}
}
else {
sort type2 title
if missing("`nocat'"){
dis as w _col(4) " `seminar_paper' >>"`"{stata "songbl `num'": `num'}"'"
post songbl_post (" `seminar_paper' >> `num'" )
`gap'
`gap1'
}
}
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
dis as y "`title'"
dis as y "`link'"
post songbl_post ("`title'")
post songbl_post ("`link'")
`gap'
`gap1'
}
}
use "`html_text_dta'", clear
if missing("`nocat'"){
post songbl_post (" " )
dis ""
}
}
}
dis ""
dis as txt "{hline 24} 分享复制以上内容 {hline 24}"
if `m'>=10{
dis in red _n "小提示:建议分多次复制到微信对话框,每次 10 行,否则超链接无法生效"
dis in red " 分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
else{
dis in red _n "小提示:分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
}
if "`wurl'" !=""{
dis ""
dis as txt _n "{hline 24} wurl文本格式 {hline 24}"
post songbl_post ("------------------------ wurl文本格式 ------------------------")
dis as txt
post songbl_post (" ")
if missing("`paper'"){
dis as res "* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace"
dis as res "* 查看更多内容请在 STATA 窗口输入代码:songbl `class'"
post songbl_post ("* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace")
post songbl_post ("* 查看更多内容请在 STATA 窗口输入代码:songbl `class'")
}
else {
dis as res "* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace"
dis as res "* 查看更多内容请在 STATA 窗口输入代码:songbl `class',paper"
post songbl_post ("* 以下内容由 -songbl- 命令生成,安装命令:ssc install songbl,replace")
post songbl_post ("* 查看更多内容请在 STATA 窗口输入代码:songbl `class',paper")
}
dis as txt
post songbl_post (" ")
qui levelsof seminar_paper , local(seminar_paper)
local m=_N
foreach seminar_paper in `seminar_paper' {
use "`html_text_dta'", clear
qui keep if seminar_paper=="`seminar_paper'"
qui levelsof style , local(number)
foreach num in `number' {
qui keep if style=="`num'"
local n=_N
if `n'>0{
if strmatch("`num'","*学术论文*") ==1 {
sort title
if missing("`nocat'"){
local name = plural(2,"`num'","-学术论文")
if missing("`paper'"){
dis as w _col(4) " 论文 >>"`"{stata "songbl `name'": `name'}"'"
post songbl_post (" 论文 >> `name'")
`gap'
`gap1'
}
else{
dis as w _col(4) " 论文 >>"`"{stata "songbl `name',paper": `name'}"'"
post songbl_post (" 论文 >> `name'")
`gap'
`gap1'
}
}
}
else {
sort type2 title
if missing("`nocat'"){
dis as w _col(4) " `seminar_paper' >>"`"{stata "songbl `num'": `num'}"'"
post songbl_post (" `seminar_paper' >> `num'" )
`gap'
`gap1'
}
}
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
if `n'==1{
dis as y "`title': `link'"
post songbl_post ("`title': `link'")
}
else {
dis as y "`i'. `title': `link'"
post songbl_post ("`i'. `title': `link'")
}
`gap'
`gap1'
}
}
use "`html_text_dta'", clear
if missing("`nocat'"){
post songbl_post (" " )
dis ""
}
}
}
dis ""
dis as txt "{hline 24} 分享复制以上内容 {hline 24}"
if `m'>=10{
dis in red _n "小提示:建议分多次复制到微信对话框,每次 10 行,否则超链接无法生效"
dis in red " 分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
else{
dis in red _n "小提示:分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
}
if "`mlink'" !=""{
dis ""
dis as txt _n "{hline 24} mlik文本格式 {hline 24}"
post songbl_post ("~~------------------------ mlink文本格式 ------------------------~~")
dis as txt
post songbl_post (" ")
if missing("`paper'"){
dis as res "> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**"
dis as res "> 查看更多内容请在 STATA 窗口输入代码:**songbl `class'**"
post songbl_post ("> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**")
post songbl_post ("> 查看更多内容请在 STATA 窗口输入代码:**songbl `class'**")
}
else {
dis as res "> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**"
dis as res "> 查看更多内容请在 STATA 窗口输入代码:**songbl `class',paper**"
post songbl_post ("> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**")
post songbl_post ("> 查看更多内容请在 STATA 窗口输入代码:**songbl `class',paper**")
}
post songbl_post ("---")
dis as txt "---"
qui levelsof seminar_paper , local(seminar_paper)
foreach seminar_paper in `seminar_paper' {
use "`html_text_dta'", clear
qui keep if seminar_paper=="`seminar_paper'"
qui levelsof style , local(number)
foreach num in `number' {
qui keep if style=="`num'"
local n=_N
if `n'>0{
if strmatch("`num'","*学术论文*") ==1 {
sort title
if missing("`nocat'"){
local name = plural(2,"`num'","-学术论文")
if missing("`paper'"){
dis as w _col(4) "### 论文 >>"`"{stata "songbl `name'": `name'}"'"
post songbl_post ("### 论文 >> `name'")
`gap'
`gap1'
}
else{
dis as w _col(4) "### 论文 >>"`"{stata "songbl `name',paper": `name'}"'"
post songbl_post ("### 论文 >> `name'")
`gap'
`gap1'
}
}
}
else {
sort type2 title
if missing("`nocat'"){
dis as w _col(4) "### `seminar_paper' >>"`"{stata "songbl `num'": `num'}"'"
post songbl_post ("### `seminar_paper' >> `num'" )
`gap'
`gap1'
}
}
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
dis as y "- [`title'](`link')"
post songbl_post ("- [`title'](`link')")
`gap'
`gap1'
}
}
use "`html_text_dta'", clear
if missing("`nocat'"){
post songbl_post (" " )
dis ""
}
}
}
dis ""
dis as txt "{hline 24} 分享复制以上内容 {hline 24}"
dis in red _n "小提示:分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
if "`mtext'" !=""{
dis ""
dis as txt _n "{hline 24} mtext文本格式 {hline 24}"
post songbl_post ("~~------------------------ mtext文本格式 ------------------------~~")
dis as txt
post songbl_post (" ")
if missing("`paper'"){
dis as res "> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**"
dis as res "> 查看更多内容请在 STATA 窗口输入代码:**songbl `class'**"
post songbl_post ("> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**")
post songbl_post ("> 查看更多内容请在 STATA 窗口输入代码:**songbl `class'**")
}
else {
dis as res "> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**"
dis as res "> 查看更多内容请在 STATA 窗口输入代码:**songbl `class',paper**"
post songbl_post ("> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**")
post songbl_post ("> 查看更多内容请在 STATA 窗口输入代码:**songbl `class',paper**")
}
dis as txt "---"
post songbl_post ("---")
qui levelsof seminar_paper , local(seminar_paper)
foreach seminar_paper in `seminar_paper' {
use "`html_text_dta'", clear
qui keep if seminar_paper=="`seminar_paper'"
qui levelsof style , local(number)
foreach num in `number' {
qui keep if style=="`num'"
local n=_N
if `n'>0{
if strmatch("`num'","*学术论文*") ==1 {
sort title
if missing("`nocat'"){
local name = plural(2,"`num'","-学术论文")
if missing("`paper'"){
dis as w _col(4) "### 论文 >>"`"{stata "songbl `name'": `name'}"'"
post songbl_post ("### 论文 >> `name'")
`gap'
`gap1'
}
else{
dis as w _col(4) "### 论文 >>"`"{stata "songbl `name',paper": `name'}"'"
post songbl_post ("### 论文 >> `name'")
`gap'
`gap1'
}
}
}
else {
sort type2 title
if missing("`nocat'"){
dis as w _col(4) "### `seminar_paper' >>"`"{stata "songbl `num'": `num'}"'"
post songbl_post ("### `seminar_paper' >> `num'" )
`gap'
`gap1'
}
}
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
dis as y "[`title'](`link')"
post songbl_post ("[`title'](`link')")
`gap'
`gap1'
}
}
use "`html_text_dta'", clear
if missing("`nocat'"){
post songbl_post (" " )
dis ""
}
}
}
dis ""
dis as txt "{hline 24} 分享复制以上内容 {hline 24}"
dis in red _n "小提示:分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
if "`murl'" !=""{
dis ""
dis as txt _n "{hline 24} murl文本格式 {hline 24}"
post songbl_post ("~~------------------------ murl文本格式 ------------------------~~")
dis as txt
post songbl_post (" ")
if missing("`paper'"){
dis as res "> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**"
dis as res "> 查看更多内容请在 STATA 窗口输入代码:**songbl `class'**"
post songbl_post ("> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**")
post songbl_post ("> 查看更多内容请在 STATA 窗口输入代码:**songbl `class'**")
}
else {
dis as res "> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**"
dis as res "> 查看更多内容请在 STATA 窗口输入代码:**songbl `class',paper**"
post songbl_post ("> 以下内容由 -songbl- 命令生成,安装命令:**ssc install songbl,replace**")
post songbl_post ("> 查看更多内容请在 STATA 窗口输入代码:**songbl `class',paper**")
}
dis as txt "---"
post songbl_post ("---")
qui levelsof seminar_paper , local(seminar_paper)
foreach seminar_paper in `seminar_paper' {
use "`html_text_dta'", clear
qui keep if seminar_paper=="`seminar_paper'"
qui levelsof style , local(number)
foreach num in `number' {
qui keep if style=="`num'"
local n=_N
if `n'>0{
if strmatch("`num'","*学术论文*") ==1 {
sort title
if missing("`nocat'"){
local name = plural(2,"`num'","-学术论文")
if missing("`paper'"){
dis as w _col(4) "### 论文 >>"`"{stata "songbl `name'": `name'}"'"
post songbl_post ("### 论文 >> `name'")
`gap'
`gap1'
}
else{
dis as w _col(4) "### 论文 >>"`"{stata "songbl `name',paper": `name'}"'"
post songbl_post ("### 论文 >> `name'")
`gap'
`gap1'
}
}
}
else {
sort type2 title
if missing("`nocat'"){
dis as w _col(4) "### `seminar_paper' >>"`"{stata "songbl `num'": `num'}"'"
post songbl_post ("### `seminar_paper' >> `num'" )
`gap'
`gap1'
}
}
forvalues i = 1/`n' {
local link=link[`i']
local title=title[`i']
if `n'==1{
dis ""
dis as y "[`title'](`link')"
post songbl_post ("")
post songbl_post ("[`title'](`link')")
}
else {
dis as y "`i'. [`title'](`link')"
post songbl_post ("`i'. [`title'](`link')")
}
`gap'
`gap1'
}
}
use "`html_text_dta'", clear
if missing("`nocat'"){
post songbl_post (" " )
dis ""
}
}
}
dis ""
dis as txt "{hline 24} 分享复制以上内容 {hline 24}"
dis in red _n "小提示:分享长链接直接复制会断行。建议使用 save(txt) 或者 replace 选项,利用 TXT 文档 or STATA 打开"
}
postclose songbl_post
use "`songbl_post'", clear
cap format %-200s Share
}
if ("`replace'"!="") {
qui cap keep link title style type seminar_paper
qui cap label variable link "链接"
qui cap label variable title "标题"
qui cap label variable style "分类"
qui cap label variable type "来源"
qui cap label variable seminar_paper "论文 or 推文"
browse
}
if ("`save'"!="") {
qui export delimited Share using "`Share_txt'.`save'" , ///
novar nolabel delimiter(tab) replace
view browse "`Share_txt'.`save'"
}
if "`time'"!=""{
timer off 1
qui timer list 1
local timer =strofreal(`r(t1)',"%9.3f")
local cur_time "`year'年`month'月`day'日"
if "`paper'"==""{
dis as txt
dis as res _col(4) `"{stata "songbl ":【快捷查看分类推文】}"'
dis as res _col(4) `"搜索共耗时 `timer' 秒"'
dis as res _col(4) `"目前北京时间:`cur_time' `c(current_time)' "'
}
else{
dis as txt
dis as res _col(4) `"{stata "songbl paper"【快捷查看分类论文】}"'
dis as res _col(4) `"搜索共耗时 `timer' 秒"'
dis as res _col(4) `"目前北京时间:`cur_time' `c(current_time)' "'
}
}
cap erase "`html_text'.txt"
if ("`replace'"=="") {
restore
}
end
*==============================================================================*
****Sub programs****
*==============================================================================*
capture program drop dingwei
program define dingwei , rclass
version 10.0
syntax anything (name = varname ) [,C(string) D]
qui{
tempvar new_varname row row_n row_varname
egen `new_varname' = concat(`varname')
local varname `new_varname'
if missing("`d'") {
gen `row'=1 if index(`varname',"`c'")
}
else{
gen `row'=1 if strmatch(`varname',"`c'")
}
gen `row_n'=_n
tempfile mas
qui save "`mas'"
keep if `row'==1
local j =_N
levelsof `row_n' , local(number)
return local N `j'
return local row_n `number'
}
use "`mas'", clear
end
*==============================================================================*
****Sub programs****
*==============================================================================*
cap program drop gitee
program define gitee
version 14
syntax anything( name = git) ,Cla(string)
if "`cla'"=="do"{
local URL `"`git'"'
tempfile html_text
copy `URL' "`html_text'.`cla'", replace
doedit "`html_text'.`cla'"
}
foreach i in pdf txt docx md .xls .xlsx{
if "`cla'"=="`i'"{
local URL `"`git'"'
tempfile html_text
copy `URL' "`html_text'.`cla'", replace
view browse "`html_text'.`cla'"
}
}
cap erase "`html_text'.txt"
end
*==============================================================================*
****Sub programs**** // 借鉴 lianxh_links
*==============================================================================*
cap program drop songbl_links
program define songbl_links
version 8
syntax [anything] [,URL(string)]
qui{
preserve
clear
tempfile html_text
cap copy `"`url'"' "`html_text'.txt", replace
local times = 0
while _rc ~= 0 {
local times = `times' + 1
sleep 1000
cap copy `"`URL'"' "`html_text'.txt", replace
if `times' > 10 {
disp as error "Internet speeds is too low to get the data"
exit 601
}
}
infix strL v 1-100000 using "`html_text'.txt", clear
split v, p("++")
cap keep v1 v2
local name =v1[1] //导航标题
local number1=v1[2]
local number2=v1[3]
local number3=v1[4]
count if v2==""
local r(N)=`r(N)'-7
forvalues i=1/`r(N)'{
local j=`i'+4
local c`i'=v1[`j']
}
drop if v2==""
}
local G = 6 // 每个专题显示个数
local N = _N // 类别数
local NN = int(`N'/`G') // 行数
local mod = mod(`N',6) // 剩余个数
dis in w _col(`number1') _n _skip(`number2') `"`name'"' _n
local k1=1
local m=5
forvalues o = 1/`NN'{
forvalues i=1/6{
local a`k`i''= v1[`k`i'']
local b`k`i''= v2[`k`i'']
local j =`i'+1
local k`j' =`k`i''+1
}
forvalues i=1/6{
if strmatch("`b`k`i'''","*http*")==1{
local browse_stata`i' browse
}
else{
local browse_stata`i' stata
}
}
dis in w " `c`m'': " ///
_col(`c1') `"{`browse_stata1' "`b`k1''":`a`k1''}"' ///
_col(`c2') `"{`browse_stata2' "`b`k2''":`a`k2''}"' ///
_col(`c3') `"{`browse_stata3' "`b`k3''":`a`k3''}"'
dis in w _col(`number3') ///
_col(`c1') `"{`browse_stata4' "`b`k4''":`a`k4''}"' ///
_col(`c2') `"{`browse_stata5' "`b`k5''":`a`k5''}"' ///
_col(`c3') `"{`browse_stata6' "`b`k6''":`a`k6''}"' ///
_n
local k1=`k1'+6
local m=`m'+1
}
forvalues i=1/5{
local a_n`i' =`NN'*6+`i'
local a`a_n`i''=v1[`a_n`i'']
local b`a_n`i''=v2[`a_n`i'']
}
forvalues i=1/6{
if strmatch("`b`a_n`i'''","*http*")==1{
local browse_stata`i' browse
}
else{
local browse_stata`i' stata
}
}
if `mod'==1{
dis in w " `c`m'': " ///
_col(`c1') `"{`browse_stata1' "`b`a_n1''":`a`a_n1''}"'
}
if `mod'==2{
dis in w " `c`m'': " ///
_col(`c1') `"{`browse_stata1' "`b`a_n1''":`a`a_n1''}"' ///
_col(`c2') `"{`browse_stata2' "`b`a_n2''":`a`a_n2''}"'
}
if `mod'==3{
dis in w " `c`m'': " ///
_col(`c1') `"{`browse_stata1' "`b`a_n1''":`a`a_n1''}"' ///
_col(`c2') `"{`browse_stata2' "`b`a_n2''":`a`a_n2''}"' ///
_col(`c3') `"{`browse_stata3' "`b`a_n3''":`a`a_n3''}"'
}
if `mod'==4{
dis in w " `c`m'': " ///
_col(`c1') `"{`browse_stata1' "`b`a_n1''":`a`a_n1''}"' ///
_col(`c2') `"{`browse_stata2' "`b`a_n2''":`a`a_n2''}"' ///
_col(`c3') `"{`browse_stata3' "`b`a_n3''":`a`a_n3''}"'
dis in w _col(`number3') ///
_col(`c1') `"{`browse_stata4' "`b`a_n4''":`a`a_n4''}"'
}
if `mod'==5{
dis in w " `c`m'': " ///
_col(`c1') `"{`browse_stata1' "`b`a_n1''":`a`a_n1''}"' ///
_col(`c2') `"{`browse_stata2' "`b`a_n2''":`a`a_n2''}"' ///
_col(`c3') `"{`browse_stata3' "`b`a_n3''":`a`a_n3''}"'
dis in w _col(`number3') ///
_col(`c1') `"{`browse_stata4' "`b`a_n4''":`a`a_n4''}"' ///
_col(`c2') `"{`browse_stata5' "`b`a_n5''":`a`a_n5''}"'
}
cap erase "`html_text'.txt"
restore
end
cap program drop songbl_links1
program define songbl_links1
version 8
syntax [anything][,URL(string)] ///
qui{
preserve
clear
tempfile html_text
cap copy `"`url'"' "`html_text'.txt", replace
local times = 0
while _rc ~= 0 {
local times = `times' + 1
sleep 1000
cap copy `"`url'"' "`html_text'.txt", replace
if `times' > 10 {
disp as error "Internet speeds is too low to get the data"
exit 601
}
}
infix strL v 1-100000 using "`html_text'.txt", clear
split v, p("++")
cap keep v1 v2
}
local name =v1[1] //导航标题
local number1=v1[2]
local number2=v1[3]
local c1 =v1[4]
local c2 =v1[5]
local c3 =v1[6]
qui drop if v2==""
local G = 3 // 每行显示个数
local N = _N // 类别数
local NN = int(`N'/`G') // 行数
local mod = mod(`N',3) //剩余个数
dis in w _col(`number1') _n _skip(`number2') `"`name'"' _n
local k1=1
forvalues o = 1/`NN'{
local a`k1'= v1[`k1']
local b`k1'= v2[`k1']
local k2=`k1'+1
local a`k2'= v1[`k2']
local b`k2'= v2[`k2']
local k3=`k1'+2
local a`k3'= v1[`k3']
local b`k3'= v2[`k3']
if strmatch("`b`k1''","*http*")==1{
dis in w _col(`c1') `"{browse "`b`k1''":`a`k1''}"' _continue
}
else{
dis in w _col(`c1') `"{stata "`b`k1''":`a`k1''}"' _continue
}
if strmatch("`b`k2''","*http*")==1{
dis in w _col(`c2') `"{browse "`b`k2''":`a`k2''}"' _continue
}
else{
dis in w _col(`c2') `"{stata "`b`k2''":`a`k2''}"' _continue
}
if strmatch("`b`k3''","*http*")==1{
dis in w _col(`c3') `"{browse "`b`k3''":`a`k3''}"' _n
}
else{
dis in w _col(`c3') `"{stata "`b`k3''":`a`k3''}"' _n
}
local k1=`k1'+3
}
local a_n1 =`NN'*3+1
local a_n2 =`NN'*3+2
local a`a_n1'=v1[`a_n1']
local b`a_n1'=v2[`a_n1']
local a`a_n2'=v1[`a_n2']
local b`a_n2'=v2[`a_n2']
if `mod'==1{
if strmatch("`b`k1''","*http*")==1{
dis in w _col(`c1') `"{browse "`b`a_n1''":`a`a_n1''}"'
}
else{
dis in w _col(`c1') `"{stata "`b`a_n1''":`a`a_n1''}"'
}
}
if `mod'==2{
if strmatch("`b`k1''","*http*")==1{
dis in w _col(`c1') `"{browse "`b`a_n1''":`a`a_n1''}"' _continue
}
else {
dis in w _col(`c1') `"{stata "`b`a_n1''":`a`a_n1''}"' _continue
}
if strmatch("`b`k1''","*http*")==1{
dis in w _col(`c2') `"{browse "`b`a_n2''":`a`a_n2''}"'
}
else{
dis in w _col(`c2') `"{stata "`b`a_n2''":`a`a_n2''}"'
}
}
cap erase "`html_text'.txt"
restore
end
*! Verion: 3.0
*! Update: 2021/1/20 12:32
*! Verion: 4.0
*! Update: 2021/3/16 06:35
*1 增加了 NOCat Mlink MText Navigation
*2 把论文与推文分开储存,提高搜索速度
*3 增加动态导航功能。
*! Verion: 5.0
*! Update: 2021/4/12
*1 增加了 SAVE(string) 功能,利用文档打开分享的内容。
*2 增加了 REPLACE 功能,生成分享内容的 STATA 数据集。
*3 增加了 TIME 功能,输出检索结果的末尾带有返回推文分类目录或者论文分类目录的快捷方式。
*4 更改了分享功能的输出风格。
*! Verion: 6.0
*! Update: 2021/5/16
*1 修复了在stata 17上批量获取导航链接的错误。
*2 修复了置顶推文发生的错误。
*3 分享推文时,删除了非链接的资源。
*4 修复了无法同时使用命令与链接的错误,例如 use www.xxx.dta
*5 上线了资源上传分享的功能
*6 资源类型从专题到论文,更变为推文、论文、数据、视频等
*7 更改了songbl new 的输出风格。
*8 增加了划线输出风格。line
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/morcc7/stata_ado.git
[email protected]:morcc7/stata_ado.git
morcc7
stata_ado
stata_ado
master

搜索帮助