summaryrefslogtreecommitdiff
path: root/desk/ted/tw.hoon
blob: 1fffee59d25df7cc27dbc42b889860ecc2e8ed3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/-  spider, jon=twatter-json
/+  strandio, sr=sortug, w2=web2, lib=twatter
=,  strand=strand:spider
=,  dejs-soft:format
=,  strand-fail=strand-fail:libstrand:spider
=<  run
|%
++  get-body
|=  res=client-response:iris  ^-  @t
  ?.  ?=(%finished -.res)  ''
  ?~  full-file.res  ''
  q.data.u.full-file.res
++  coki-to-string
|=  t=twatter-creds:w2  ^-  cord
  =/  at  (trip auth-token.t)
  =/  ct0  (trip ct0.t)
  =/  kdt  (trip kdt.t)
  =/  twid  (trip twid.t)
  %-  crip
  "auth_token={at};ct0={ct0};kdt={kdt};twid={twid};"
::
++  run
  ^-  thread:spider
  |=  arg=vase
  ~&  >  arg=arg
  =/  m  (strand vase)
  ^-  form:m
  =/  coki  muh:w2
  =/  csrf  ct0.coki
  =/  coki-string  (coki-to-string coki)
  =/  headers  (logged-headers:lib coki-string csrf)
  |^
  :: =/  req  !<(twatter-action:w2 arg)
  =/  req=twatter-action:w2  [%user 'spandrell4']
  ?+  -.req  (pure:m !>(%bad))
    %user  (fetch-tw-user +.req)
  ==
  ++  fetch-tw-user
  |=  username=@t
    =/  vars  (build-variables:lib ~[['screen_name' %s username]])
    =/  url  %-  crip  (weld (burl:lib user-by-name:urls:lib) "?variables={vars}&features={features:lib}")
    =/  req1  [%'GET' url headers ~]
    ;<  ~  bind:m  (send-request:strandio req1)
    ;<  res1=client-response:iris  bind:m  take-client-response:strandio
    =/  body1=@t  (get-body res1)
    :: ~&  >>  body1
    =/  j  (de:json:html body1)
    ?~  j  (pure:m !>(%bad-js))
    =/  dejs  (username:jon u.j)
    ?~  dejs  (pure:m !>(%bad-js))
    =/  user-id=@t  u.dejs
    =/  url2  %-  crip  (weld (burl:lib user-tweets:urls:lib) (userid-params:lib user-id))
    =/  req2  [%'GET' url2 headers ~]
    ;<  ~  bind:m  (send-request:strandio req2)
    ;<  res2=client-response:iris  bind:m  take-client-response:strandio
    =/  body2  (get-body res2)
    =/  jon  (de:json:html body2)
    ?~  jon  (pure:m !>(%bad-json))
    (pure:m !>(u.jon))
  --
--