Add old twitter app.

This commit is contained in:
C. Guy Yarvin 2014-08-10 20:49:56 -07:00
parent fe9c4c8a85
commit 9805fd21fd
6 changed files with 389 additions and 40 deletions

114
main/app/a-twit/core.hook Normal file
View File

@ -0,0 +1,114 @@
/+ twitter
!:
=> |%
++ rev 0
++ axle ,[@ @]
++ gilt :: State data
$% [%json p=json] :: JSON format
[%html p=@t]
[%hymn p=manx] :: HTML format
==
++ gift :: Message data
$% [%rust gilt] :: Refresh webapp
[%rush gilt] :: Update webapp
[%mean (unit (pair term (list tank)))] :: Error, maybe w/ msg
[%nice ~] :: Response message
==
++ move ,[p=bone q=(mold note gift)] :: Arvo command
++ sign
$% $: %e
$% [%thou p=httr]
== == ==
++ note :: Arvo message
$% $: %e
$% [%them p=(unit hiss)]
== == ==
++ app-key :: specific keys
:- :- 'hDDOTPfGHGlsOUbhpy6qc6XbW'
'olCkea6wm3XG4pnVCHuPIozUF2ggH1sHjnBtuT4Ai6rCOeQGzO'
:- '2485712317-R77Lpdu5rAJadRVxTXPpnxvcwS0IfNG7QEzLPty'
'a41d83XId0P7QQbodkPYv3zxoEL0Cq9EsN2eXZBZAwAWA'
--
|_ [hid=hide vat=axle]
::
++ root :: App root location
/(scot %p our.hid)/main/(scot %da lat.hid)/app/[app.hid]
::
++ incl :: Include scripts
|= wal=wall
%+ turn wal
|= tape ;script(type "text/javascript", src +<);
::
++ peer :: Accept subscribes
|= [ost=bone you=ship pax=path]
^- [(list move) _+>]
?~ pax
:: [[ost %give %rust %hymn page]~ +>.$]
[[ost %pass /curl1 %e [%them (some timl)]]~ +>.$]
[~ +>.$]
::
++ poke-json
|= [ost=bone his=ship jon=json]
^- [(list move) _+>]
:: this is where you take the jon and post it to twitter.
~& [%got-json jon]
[[ost %pass /curl2 %e [%them (some (posl jon))]]~ +>.$]
::[[ost %give %nice ~]~ +>.$]
::
++ page
|= a=@t
^- manx
;html
;head
;style:"{(trip ;;(,@ .^(%cx (welp root /main/css))))}"
;* %- incl :~
"//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"
==
;title: Urbit - Twitter Test
==
;body
;div#c
;div#d
;div#twet
;div.author: @urbit_test
;div.date;
;textarea#tweetr(placeholder "What would you like to tweet?");
;input#submit(type "button", value "Send");
;input#length(type "button", value "0/140");
==
;div#time;
==
==
:: this is where you put the json from the home timeline in
:: make sure its in a script tag with the id jime
;script#jime:"{(trip a)}"
;script:"{(trip ;;(,@ .^(cx/(welp (scag 3 `path`root) /lib/urb/js))))}"
;script:"{(trip ;;(,@ .^(%cx (welp root /main/js))))}"
==
==
++ pour
|= [way=path sih=sign]
^- [(list move) _+>]
:_ +>.$
%+ turn (~(tap in (~(get ju pus.hid) ~)))
|= ost=bone
[ost %give %rust %hymn (page `@t`q:(need r.p.sih))]
++ testt
^- hiss
[(scan "http://www.example.com" auri:epur) %get ~ ~]
++ timl
^- hiss
=+ (twit `keys`app-key lat.hid `@`eny.hid)
(stat-home ~ ~)
++ posl
|= jon=json
=+ txt=`(unit ,[%tweet p=cord])`((of:jo [%tweet so:jo] ~) jon)
~& [%posl p:(need txt)]
^- hiss
=+ (twit `keys`app-key lat.hid `@`eny.hid)
(stat-upda ~[(st ~ p:(need txt))] ~)
--

117
main/app/a-twit/main.css Normal file
View File

@ -0,0 +1,117 @@
body,
textarea,
input {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
}
body {
margin-top: 4rem;
font-size: 18px;
}
input,
textarea {
font-size: 1rem;
outline: none;
}
#c {
width: 100%;
height: 100%;
}
#d,
#tweet,
.tweet,
.text,
textarea {
width: 32rem;
}
#d {
margin-left: auto;
margin-right: auto;
}
textarea {
border: 0;
height: 8rem;
line-height: 1.5rem;
margin-bottom: .3rem;
resize: none;
padding: 1rem 1px;
background-color: #f7f7f7;
}
textarea:focus {
background-color: #eee;
}
#length,
#submit {
border: 0;
color: #333;
letter-spacing: 0.01rem;
}
#length {
width 1rem;
height 1rem;
font-size: .6rem;
color: #ccc;
background-color: transparent;
}
#submit {
background-color: transparent;
border: 2px solid #5DE668;
color: #5DE668;
padding: .3rem 1rem;
font-weight: 500;
cursor: pointer;
}
#submit:hover,
#submit:focus {
background-color: #5DE668;
color: #fff;
}
#submit.disabled {
opacity: .6;
}
.text {
word-wrap:break-word;
margin-bottom: .3rem;
line-height: 1.6rem;
}
#twet {
margin-bottom: 3rem;
border-bottom: 2px solid #464646;
padding-bottom: 2rem;
}
#twet,
.tweet {
border-bottom: 1px solid #eee;
}
.tweet {
margin-bottom: 2rem;
padding-bottom: 1rem;
}
.author,
.date {
font-size: .8rem;
color: #ccc;
margin-right: .6rem;
display: inline-block;
margin-bottom: .3rem;
}
.author {
color: #888;
}

64
main/app/a-twit/main.js Normal file
View File

@ -0,0 +1,64 @@
$(function() {
checkLength = function() {
if($tweet.val().length > 140) {
short = $tweet.val().slice(0,140)
$tweet.val(short)
return false
}
}
setLength = function() {
$("#length").val($("#tweetr").val().length+"/140")
}
twoDig = function(d) {
return (d<10) ? "0"+d : d
}
setTime = function() {
d = new Date()
datestr = twoDig(d.getMonth()+1) + "-" + twoDig(d.getDate()) + "-" + d.getFullYear() + " " + twoDig(d.getHours()) + ":" + twoDig(d.getMinutes()) + ":" + twoDig(d.getSeconds())
$("#twet .date").text(datestr)
}
setInterval(setTime,1000)
setTime()
$tweet = $("#tweetr")
$time = $("#time")
$submit = $('#submit')
$tweet.focus()
$tweet[0].selectionStart = $tweet[0].selectionEnd = $tweet.val().length
$tweet.change(checkLength)
$tweet.keydown(checkLength)
$tweet.keyup(setLength)
$submit.click(function() {
tweet = $tweet.val()
$tweet.attr('disabled', true)
$submit.attr('disabled', true)
$submit.addClass('disabled')
window.urb.send({
appl:"twit",
data:{tweet:tweet}
}, function(err,res) {
console.log(arguments)
$tweet.attr('disabled', false)
$submit.attr('disabled', false)
$submit.removeClass('disabled')
$tweet.val('')
})
})
timeline = JSON.parse($('#jime')[0].innerHTML)
for(i in timeline) {
tweets = timeline[i]
d = new Date(tweets.created_at)
datestr = d.getMonth()+1 + "-" + d.getDate() + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds()
$tweets = $("<div class='tweet'></div>")
$tweets.append("<div class='author'>@urbit_test</div>")
$tweets.append("<div class='date'>"+datestr+"</div>")
$tweets.append("<div class='text'>"+tweets.text+"</div>")
$time.append($tweets)
}
})

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,8 @@
/+ twitter /+ twitter
!: !:
=> |% => |%
++ rev 0 ++ axle ,@t :: Just JSON
++ axle ,[@ @] ++ gilt :: subscriptions frames
++ gilt :: State data
$% [%json p=json] :: JSON format $% [%json p=json] :: JSON format
[%html p=@t] [%html p=@t]
[%hymn p=manx] :: HTML format [%hymn p=manx] :: HTML format
@ -23,40 +22,52 @@
$% $: %e $% $: %e
$% [%them p=(unit hiss)] $% [%them p=(unit hiss)]
== == == == == ==
++ app-key :: specific keys ++ app-key :: hardcoded keys!
:- :- 'hDDOTPfGHGlsOUbhpy6qc6XbW' :- :- 'hDDOTPfGHGlsOUbhpy6qc6XbW'
'olCkea6wm3XG4pnVCHuPIozUF2ggH1sHjnBtuT4Ai6rCOeQGzO' 'olCkea6wm3XG4pnVCHuPIozUF2ggH1sHjnBtuT4Ai6rCOeQGzO'
:- '2485712317-R77Lpdu5rAJadRVxTXPpnxvcwS0IfNG7QEzLPty' :- '2485712317-R77Lpdu5rAJadRVxTXPpnxvcwS0IfNG7QEzLPty'
'a41d83XId0P7QQbodkPYv3zxoEL0Cq9EsN2eXZBZAwAWA' 'a41d83XId0P7QQbodkPYv3zxoEL0Cq9EsN2eXZBZAwAWA'
-- --
|_ [hid=hide vat=axle] |_ [hid=hide vat=axle]
::
++ prep
|= old=(unit)
~& %hose-state
[~ +>]
:: ::
++ root :: App root location ++ root :: internal location
/(scot %p our.hid)/main/(scot %da lat.hid)/app/[app.hid] /(scot %p our.hid)/main/(scot %da lat.hid)/app/[app.hid]
:: ::
++ incl :: Include scripts ++ incl :: include scripts
|= wal=wall |= wal=wall
%+ turn wal %+ turn wal
|= tape ;script(type "text/javascript", src +<); |= tape ;script(type "text/javascript", src +<);
:: ::
++ peer :: Accept subscribes ++ peer :: accept subscriber
|= [ost=bone you=ship pax=path] |= [ost=bone you=ship pax=path]
^- [(list move) _+>] ^- [(list move) _+>]
:_ +>.$
?~ pax ?~ pax
:: [[ost %give %rust %hymn page]~ +>.$] [ost %give %rust %hymn page]~
[[ost %pass /curl1 %e [%them (some timl)]]~ +>.$] ?>(?=([%time ~] pax) ~)
[~ +>.$] ::
:: ++ poke-json :: client message
++ poke-json
|= [ost=bone his=ship jon=json] |= [ost=bone his=ship jon=json]
^- [(list move) _+>] ^- [(list move) _+>]
:: this is where you take the jon and post it to twitter. ~& [%got-json ost]
~& [%got-json jon] =+ jop=(need ((of [%tweet sa] [%time sa] ~):jo jon))
[[ost %pass /curl2 %e [%them (some (posl jon))]]~ +>.$] ~& [%got-jop ost]
::[[ost %give %nice ~]~ +>.$] =+ key=-.jop
:_ +>.$
:_ ~
?: ?=(%tweet key)
~& [%tweet-pax /tweet/(scot %ud ost)]
[ost %pass /tweet/(scot %ud ost) %e [%them (some (posl jon))]]
?: ?=(%time key)
[ost %give %nice ~]
!!
:: ::
++ page ++ page
|= a=@t
^- manx ^- manx
;html ;html
;head ;head
@ -79,34 +90,61 @@
;div#time; ;div#time;
== ==
== ==
:: this is where you put the json from the home timeline in
:: make sure its in a script tag with the id jime
;script#jime:"{(trip a)}"
;script:"{(trip ;;(,@ .^(cx/(welp (scag 3 `path`root) /lib/urb/js))))}" ;script:"{(trip ;;(,@ .^(cx/(welp (scag 3 `path`root) /lib/urb/js))))}"
;script:"{(trip ;;(,@ .^(%cx (welp root /main/js))))}" ;script:"{(trip ;;(,@ .^(%cx (welp root /main/js))))}"
== ==
== ==
++ pour ::
|= [way=path sih=sign] ++ pour-time
|= [pax=path sih=sign]
^- [(list move) _+>] ^- [(list move) _+>]
~& %pour-time
:_ +>.$ :_ +>.$
%+ turn (~(tap in (~(get ju pus.hid) ~))) =. vat `@t`q:(need r.p.sih)
|= ost=bone :_ =. vat `@t`q:(need r.p.sih) +>.$
[ost %give %rust %hymn (page `@t`q:(need r.p.sih))] %+ turn
%+ skim (~(tap by sup.hid))
|= [ost=bone his=ship pax=path]
~& pax
?=([%time ~] pax)
|= [ost=bone his=ship pax=path]
~& [%pour-time-give
=- [ost give/rush/json/-]
(rash vat apex:poja)
::
++ pour-tweet
|= [pax=path sih=sign]
^- [(list move) _+>]
=+ ost=(slav %ud -.+.pax)
:_ +>.$
:~ [ost %give %nice ~]
[ost %pass /time %e [%them (some timl)]]
==
::
++ pour
|= [pax=path sih=sign]
^- [(list move) _+>]
~& [%pour pax]
?: ?=([%time ~] pax)
(pour-time pax sih)
?> ?=([%tweet ~] pax)
(pour-tweet pax sih)
::
++ testt ++ testt
^- hiss ^- hiss
[(scan "http://www.example.com" auri:epur) %get ~ ~] [(scan "http://www.example.com" auri:epur) %get ~ ~]
::
++ timl ++ timl
^- hiss ^- hiss
~& %request-timeline
=+ (twit `keys`app-key lat.hid `@`eny.hid) =+ (twit `keys`app-key lat.hid `@`eny.hid)
(stat-home ~ ~) (stat-home ~ ~)
::
++ posl ++ posl
|= jon=json |= jon=json
~& [%posl jon]
=+ txt=`(unit ,[%tweet p=cord])`((of:jo [%tweet so:jo] ~) jon) =+ txt=`(unit ,[%tweet p=cord])`((of:jo [%tweet so:jo] ~) jon)
~& [%posl p:(need txt)] ~& [%posl-txt txt]
^- hiss ^- hiss
=+ (twit `keys`app-key lat.hid `@`eny.hid) =+ (twit `keys`app-key lat.hid `@`eny.hid)
(stat-upda ~[(st ~ p:(need txt))] ~) (stat-upda ~[(st ~ p:(need txt))] ~)

View File

@ -50,15 +50,30 @@ $(function() {
}) })
}) })
timeline = JSON.parse($('#jime')[0].innerHTML) render = function(timeline) {
for(i in timeline) { for(i in timeline) {
tweets = timeline[i] tweets = timeline[i]
d = new Date(tweets.created_at) d = new Date(tweets.created_at)
datestr = d.getMonth()+1 + "-" + d.getDate() + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() datestr = d.getMonth()+1 + "-" + d.getDate() + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds()
$tweets = $("<div class='tweet'></div>") $tweets = $("<div class='tweet'></div>")
$tweets.append("<div class='author'>@urbit_test</div>") $tweets.append("<div class='author'>@urbit_test</div>")
$tweets.append("<div class='date'>"+datestr+"</div>") $tweets.append("<div class='date'>"+datestr+"</div>")
$tweets.append("<div class='text'>"+tweets.text+"</div>") $tweets.append("<div class='text'>"+tweets.text+"</div>")
$time.append($tweets) $time.append($tweets)
}
}
window.urb.subscribe({
appl:"twit",
path:"/time"
}, function(err,res) {
console.log('subscr')
console.log(arguments)
})
try {
timeline = JSON.parse($('#jime')[0].innerHTML)
render(timeline)
} catch (e) {
} }
}) })