Example #1
0
def get_challenge(home, challenge_id, hotspot_address_map):
    hotspot_address = home['address']
    challenge_activity = requests.get(
        f'https://explorer.helium.foundation/api/challenges/{challenge_id}')
    path = challenge_activity.json()['data']['pathElements']
    print(
        "  result     witnesses  distance path     target                    receipt?"
    )
    for i, elem in enumerate(path):
        if home['address'] == elem['address']:
            # even if these two are the same the lat/lon may not be equal. yay for floats and rounding.
            dist_txt = "   ----"
        else:
            dist = geo(loc(home), loc(elem)).miles
            dist_txt = f"{dist:7.2f}"
        tgt = safe_name_from_address(hotspot_address_map, elem['address'])
        rct_tgt = safe_name_from_address(hotspot_address_map,
                                         elem['receipt'].get('address'))
        receipt_label = "not received"
        if rct_tgt == tgt:
            receipt_label = "received"

        print(
            f"  {elem['result']:10} {len(elem['witnesses']):5}      {dist_txt}  {elem['receipt'].get('origin', ''):8} {tgt:25} {receipt_label}"
        )
Example #2
0
def main():
  homeid = None
  if len(sys.argv) > 1:
    homeid = normalize_name(' '.join(sys.argv[1:]))
  else:
    print("give your hotspot id (one-two-three) as the argument. spaces or dashes are fine.")

  print(f"normalized name: {homeid}")

  home = None
  hotspot = {}
  r = requests.get('https://network.helium.com/fetchHotspots')
  for h in r.json():
    # save them by name
    stdname = normalize_name(h['name'])
    hotspot[stdname] = h
    if stdname == homeid:
      home = h

  if not home:
    print(f"eep, we didn't find your hotspot name ({homeid}).")
    sys.exit(-1)

  hotspots = []

  # now compare them to see if they're local
  print(f"dist score name")
  for h_id, h in hotspot.items():
    dist = geo(loc(home), loc(h)).miles
    if dist < 30:
      score = int(h['score'] * 100)
      coord = f"{h['lat']:3.4f}, {h['lng']:3.4f}"
      name = h['name']
      result = (dist, score, name, coord)
      hotspots.append(result)

  for result in reversed(sorted(hotspots, key=lambda x: x[0])):
    print(f"{result[0]:4.1f} {result[1]:5} {result[2]:30} {result[3]}")

  # now pull peeps who have witnessed us: https://tedder.me/lols/witness-me-2.gif
  witret = requests.get(f'https://explorer.helium.foundation/api/witnesses/{home["address"]}')
  data = witret.json().get('data')
  if len(data):
    print(f"\nhotspot name                   count    rssi  witness time")
    for h in sorted(data, key=lambda x: x.get('recent_time')):
      # h = dict of pocs that saw us
      hist = h['hist']
      rssi = max(hist, key=hist.get)
      count = sum(hist.values())
      print(f"{h['name']:25} {count:10}   {rssi:5}  {datetime.datetime.fromtimestamp(h['recent_time']/1000**3).isoformat(timespec='minutes')}")
  # save them by name
  stdname = normalize_name(h['name'])
  hotspot[stdname] = h
  if stdname == homeid:
    home = h

if not home:
  print(f"eep, we didn't find your hotspot name ({homeid}).")
  sys.exit(-1)

hotspots = []

# now compare them to see if they're local
print(f"dist score name")
for h_id,h in hotspot.items():
  dist = geo( loc(home), loc(h) ).miles
  if dist < 30:
    score = int(h['score']*100)
    coord = f"{h['lat']:3.4f}, {h['lng']:3.4f}"
    name = h['name']
    result = (dist, score, name, coord)
    hotspots.append(result)

for result in reversed(sorted(hotspots, key=lambda x: x[0])):
  print(f"{result[0]:4.1f} {result[1]:5} {result[2]:30} {result[3]}")

# now pull peeps who have witnessed us: https://tedder.me/lols/witness-me-2.gif
witret = requests.get(f'https://explorer.helium.foundation/api/witnesses/{home["address"]}')
data = witret.json().get('data')
if len(data):
  print(f"\nhotspot name                   count    rssi  witness time")
Example #4
0
def main():
    homeid = None
    if len(sys.argv) > 1:
        homeid = normalize_name(' '.join(sys.argv[1:]))
    else:
        print(
            "give your hotspot id (one-two-three) as the argument. spaces or dashes are fine."
        )

    print(f"normalized name: {homeid}")

    home = None
    hotspot = {}
    r = requests.get('https://network.helium.com/fetchHotspots')
    for h in r.json():
        # save them by name
        stdname = normalize_name(h['name'])
        hotspot[stdname] = h
        if stdname == homeid:
            home = h

    if not home:
        print(f"eep, we didn't find your hotspot name ({homeid}).")
        sys.exit(-1)

    # TODO: In the future, maybe we dump this out to a file as a cache, and then
    # use it in activity.py
    neighbors = {}

    # now compare them to see if they're local
    print(f"{'dist':5} {'score':>6} {'hotspot name':35}")
    for h_id, h in hotspot.items():
        dist = geo(loc(home), loc(h)).miles
        if dist < 30:
            name = h['name']
            neighbors[name] = HotSpot(
                name=name,
                dist=dist,
                score=int(h['score'] * 100),
                coord=f"{h['lat']:3.4f}, {h['lng']:3.4f}")

    # There's probably a more readable way to do this, like ValueSortedDict with
    # a `key` function, but I couldn't get it to work
    for name, v in sorted(neighbors.items(),
                          reverse=True,
                          key=lambda item: item[1].dist):
        print(f"{v.dist:4.1f} {v.score:5} {name:35} {v.coord}")

    # now pull peeps who have witnessed us: https://tedder.me/lols/witness-me-2.gif
    witret = requests.get(
        f'https://explorer.helium.foundation/api/witnesses/{home["address"]}')
    data = witret.json().get('data')
    if len(data):
        print(
            f"\n{'hotspot name':30}{'dist':^5} {'count':^5} {'rssi':>6}{'witness time':^20}"
        )
        for h in sorted(data, key=lambda x: x.get('recent_time')):
            # h = dict of pocs that saw us
            name = h['name']
            hist = h['hist']
            dist = '0.0' if name not in neighbors else neighbors[name].dist
            rssi = max(hist, key=hist.get)
            count = sum(hist.values())
            ts = datetime.datetime.fromtimestamp(
                h['recent_time'] / 1000**3).isoformat(timespec='minutes')
            print(f"{name:30} {dist:^4.1f} {count:>5} {rssi:>6}{ts:>20}")